'How to migrate terser webpack plugin to webpack v5
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.
I am going to use webpack v5, so per doc, I removed terser: npm uninstall terser-webpack-plugin
. But I am not sure how to migrate the following settings which were set for webpack v4 + TerserPlugin:
optimization: {
minimizer: [
new TerserPlugin({
sourceMap: true,
terserOptions: {
output: {
comments: /^!/,
},
},
extractComments: false,
}),
],
},
I Could not find the document online. Can anyone help, please?
Solution 1:[1]
I'm using the following TerserPlugin config and it works well with 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
},
},
}),
],
},
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Taehyun Hwang |