uglifyjs-webpack-plugin不支持es6语法报错const 解决方法
打包出现:
static/js/chunk-vendors.d42d548c.js from UglifyJs
Unexpected token: keyword «const» [static/js/chunk-vendors.d42d548c.js:61,225864]
原因:
1,是UglifyJS不支持ES6的语法。理论上不应该啊…
2,发现uglifyjs-webpack-plugin 2.0版本的Release日志中,明确提示重新切换回到uglify-js,因为uglify-es被废弃了,如果需要ES6代码压缩,请使用terser-webpack-plugin
解决:
$ npm install terser-webpack-plugin --save-dev const TerserPlugin = require('terser-webpack-plugin') configureWebpack: { ... optimization: { minimizer: [new TerserPlugin()] } }