vue-cli 打包报错:Unexpected token: punc (()
- vue-cli 打包报错:
ERROR in static/js/vendor.ed7d2353f79d28a69f3d.js from UglifyJs
Unexpected token: punc (() [./node_modules/vue-particles/src/vue-particles/index.js:6,0][static/js/vendor.ed7d2353f79d28a69f3d.js:34830,12]
原因:上面的代码是es6的语法,由于现在还有浏览器不支持es6的语法,所以在打包的过程中要把es6转换成es5,在打包时使用了UglifyJs压缩JS,但是UglifyJs无法解析ES6,才出现了上述问题。
解决:build/webpack.base.config.js 文件中,resolve部分加入该报错插件
{
test: /\.js$/,
loader: 'babel-loader',
include: [resolve('src'), resolve('test'), resolve('/node_modules/vue-particles/src/vue-particles/index.js')]
},