【发布时间】:2018-01-24 15:25:38
【问题描述】:
babel 配置有:
{
"presets": [
["env", { "modules": false }],
"stage-2"
],
"plugins": ["transform-runtime"],
"comments": false,
"env": {
"test": {
"presets": ["env", "stage-2"],
"plugins": [ "istanbul" ]
}
}
}
和包装:
"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",
在 webpack.conf 中,我有一个(完全有货的)babel-loader 部分:
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')]
},
但我在加载某些文件时遇到错误,例如:
import Auth from './auth.js'
屈服
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
每个请求,项目结构:
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
【问题讨论】:
-
你能发布完整的
webpack.config.js吗? -
@NanduKalidindi 它是vue-cli webpack config .. 加上一些别名。它被拆分为多个文件,这使得包含完整的 webpack.config 有点难看(我们正在谈论大约 8 个文件)
-
知道了,能否请您从加载程序哈希中删除
include:键并尝试一下? -
成功了,谢谢!...那里有什么问题?
-
已添加 :) 再次感谢
标签: javascript webpack babel-loader