问题: vue项目引入echarts后执行npm run dev没有问题,但执行npm run build报错,具体报错信息如下图:
原因:
依赖resize-detector,而在./node_modules/resize-detector/esm/index.js
中包含 es6
语法,babel并未对其进行编译成 es5
语法,所以才有此错误
解决办法:
修改webpack有关babel-loader配置,对其进行编译,具体修改点:
打开webpack.base.conf.js文件找到babel-loader相关配置,修改成如下:
{ test: /\.js$/, loader: 'babel-loader', include: [resolve('src'), resolve('test'),resolve('node_modules/vue-echarts'), resolve('node_modules/resize-detector')] }