0

babel is configured with:

{
  "presets": [
    ["env", { "modules": false }],
    "stage-2"
  ],
  "plugins": ["transform-runtime"],
  "comments": false,
  "env": {
    "test": {
      "presets": ["env", "stage-2"],
      "plugins": [ "istanbul" ]
    }
  }
}

and the packages:

"babel-core": "^6.26.0",
"babel-eslint": "^8.2.1",
"babel-helper-vue-jsx-merge-props": "^2.0.3",
"babel-loader": "^7.1.2",
"babel-plugin-istanbul": "^4.1.1",
"babel-plugin-syntax-jsx": "^6.18.0",
"babel-plugin-transform-runtime": "^6.22.0",
"babel-plugin-transform-vue-jsx": "^3.5.0",
"babel-preset-env": "^1.3.2",
"babel-preset-stage-2": "^6.22.0",
"babel-register": "^6.22.0",

in webpack.conf, I have a (completely stock) babel-loader section:

function resolve (dir) {
  return path.join(__dirname, '..', dir)
}
//...
  {
    test: /\.js$/,
    loader: 'babel-loader',
    include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
  },

yet I am getting errors loading some files, such as:

import Auth from './auth.js'

yielding

 error  in ./fe-common/src/auth.js

Module parse failed: Unexpected token (11:18)
You may need an appropriate loader to handle this file type.
| export default class Auth
| {
|     authenticated = this.isAuthenticated()
|     authNotifier = new EventEmitter()
| 

 @ ./fe-common/src/main.js 19:0-28
 @ ./src/main.js
 @ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/main.js

per request, project structure:

robertotomas$ tree -d -I node_modules --noreport
.
├── build
├── config
├── fe-common
│   ├── src
│   │   ├── assets
│   │   │   └── images
│   │   ├── components
│   │   ├── css
│   │   ├── router
│   │   └── store
│   └── static
│       ├── images
│       └── jasper
├── fe-styleguide
│   ├── sass
│   │   └── partials
│   │       └── variables
│   └── src
│       ├── assets
│       │   └── images
│       │       ├── font_awesome
│       │       └── rights_owner_types
│       └── components
├── src
│   ├── assets
│   ├── components
│   ├── lang
│   │   └── en
│   ├── router
│   └── store
│       ├── UsageScenarios
│       └── lib
│           └── Schemas
├── static
└── test
    ├── e2e
    │   ├── custom-assertions
    │   └── specs
    └── unit
        └── specs
4

1 回答 1

0

我认为问题在于您include:对装载机的价值。resolve(src)没有正确搜索文件。

从您的项目结构中,您可能希望在webpack配置中使用它

{
  test: /\.js$/,
  loader: 'babel-loader',
  include: [    
    resolve('fe-common/src'),
    resolve('fe-styleguide/src'),
    resolve('src'),
    resolve('test'), 
    resolve('node_modules/webpack-dev-server/client')
  ]
},
于 2018-01-24T16:18:49.057 回答