如果您使用的是webpack v5或更高版本,则无需安装此插件。Webpack v5自带最新的简洁的Webpack插件。
我将使用webpack v5,所以根据文档,我删除了简洁的代码:npm uninstall terser-webpack-plugin
。但我不确定如何迁移为webpack v4+TerserPlugin设置的以下设置:
optimization: {
minimizer: [
new TerserPlugin({
sourceMap: true,
terserOptions: {
output: {
comments: /^!/,
},
},
extractComments: false,
}),
],
},
我在网上找不到该文档。有人能帮忙吗?
我使用以下TerserPlugin配置,它与webpack v5配合良好!
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
test: /.js(?.*)?$/i, // you should add this property
extractComments: false,
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true,
pure_funcs: ['console.log', 'console.info'], // Delete console
},
},
}),
],
},