If you are using webpack v5 or above you do not need to install this plugin. Webpack v5 comes with the latest terser-webpack-plugin out of the box.
我将使用 webpack v5,所以根据文档,我删除了 terser: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
},
},
}),
],
},
关于webpack-5 - 如何将简洁的 webpack 插件迁移到 webpack v5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66801321/