terser配置 terser-webpack-plugin
如果使用chainWebpack自定义了内部规则,请注意,webpack-chain已从v4更新到v6,最明显的变化是minimizer
配置
cli3 配置方式
const TerserPlugin = require('terser-webpack-plugin')
module.exports = {
chainWebpack: (config) => {
config.optimization.minimizer([
new TerserPlugin({ terserOptions: { compress: { drop_console: true } } })
])
}
}
详细如下
module.exports = {
optimization: {
minimizer: [
new TerserPlugin({
terserOptions: {
compress: {
warnings: false,
drop_console: true,
drop_debugger: true,
pure_funcs: ['console.log']
},
},
}),
],
},
};
cli4 配置方式
module.exports = {
chainWebpack: (config) => {
config.optimization.minimizer('terser').tap((args) => {
args[0].terserOptions.compress.drop_console = true
return args
})
}
}