webpack-js压缩(terfer-webpack-plugin)
const TerserWebpackPlugin = require("terser-webpack-plugin"); // 压缩js 代替uglify 因为uglifyjs不支持es6语法,所以用terser-webpack-plugin替代uglifyjs-webpack-plugin
plugins: [
new TerserWebpackPlugin({
// 压缩js
test: /\.js(\?.*)?$/i, //匹配参与压缩的文件
parallel: true, //使用多进程并发运行
terserOptions: {
//Terser 压缩配置
output: { comments: false },
compress: {
pure_funcs: ["console.log"], // 去除console.log
},
},
extractComments: true, //将注释剥离到单独的文件中
}),
]