我在正确配置Webpack配置时遇到一些困难。
我正在使用以下版本:
$ npm -v
6.2.0
$ npm info vue-loader version
15.2.6
$ npm info babel-loader version
7.1.5
$ npm info laravel-mix version
2.1.11
$ npm info vue2-datatable-component version
2.3.1
$ npm info babel version
6.23.0
我收到此错误:
ERROR in ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./node_modules/vue2-datatable-component/src/index.vue?vue&type=script&lang=js&
Module build failed: SyntaxError: Unexpected token (38:59)
36 | created () {
37 | // init query (make all the properties observable by using `$set`)
> 38 | const q = { limit: 10, offset: 0, sort: '', order: '', ...this.query }
| ^
39 | Object.keys(q).forEach(key => { this.$set(this.query, key, q[key]) })
40 | },
41 | watch: {
@ ./node_modules/vue2-datatable-component/src/index.vue?vue&type=script&lang=js& 1:0-139 1:160-296
@ ./node_modules/vue2-datatable-component/src/index.vue
@ ./node_modules/vue2-datatable-component/src/main.js
@ ./resources/assets/js/app.js
@ multi ./resources/assets/js/app.js
这是我在laravel混合文件中拥有的配置:
mix.webpackConfig({
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: file => (
/node_modules/.test(file) &&
!/\.vue\.js/.test(file)
)
}
],
},
plugins: [
new VueLoaderPlugin()
]
});
看来babel不在vue组件文件中运行,但是当我删除上面规则中的排除设置时,我仍然遇到相同的错误。
我整个周末都在努力解决这个问题,但步履蹒跚。