TerserWebpackPlugin
该插件使用 terser 来压缩 JavaScript。
webpack.config.js
const TerserPlugin = require('terser-webpack-plugin');
module.exports = {
optimization: {
minimize: true,
minimizer: [new TerserPlugin({
test: /\.js(\?.*)?$/i, //匹配参与压缩的文件
parallel: true, //使用多进程并发运行
terserOptions: { //Terser 压缩配置
output:{comments: false}
},
extractComments: true, //将注释剥离到单独的文件中
})],
},
};