记录升级步骤
yarn remove uglifyjs-webpack-plugin
yarn add terser-webpack-plugin@4.2.3 --dev
const TerserJsPlugin = require('terser-webpack-plugin')
plugins: [
new TerserJsPlugin({
cache: true,
sourceMap: config.build.productionSourceMap,
parallel: true, // 多进程
terserOptions: {
ecma: undefined,
warnings: false,
parse: {},
compress: {
drop_console: true,
drop_debugger: false,
pure_funcs: ['console.log'], // 移除console
},
},
}),
...]
然后就报错
return _webpack.version[0] === '4';
^
TypeError: Cannot read properties of undefined (reading '0')
at Function.isWebpack4 (D:\vue\console-parkv5-gitlab\node_modules\terser-webpack-plugin\dist\index.js:106:28)
需要把webpack升级到4+
升级过程参考https://blog.csdn.net/Uookic/article/details/115655538
延伸 webpack4 优化