I am trying to remove console.logs
with Webpack\'s Uglify plugin but it seems that Uglify plugin that comes bundled with Webpack doesn\'t have that option, its
You can use terser-webpack-plugin
compress option pure_funcs parameter to selectively drop console functions and keep the ones that you want such as console.error.
I was using "webpack": "^4.39.3" and "terser-webpack-plugin": "^2.3.2".
Steps:
1. npm install terser-webpack-plugin --save-dev
2. modify your webpack.config to set TerserPlugin
as a minimizer for optimization option.
const TerserPlugin = require('terser-webpack-plugin');
module.exports = (env) => {
return [{
entry: '...',
mode: 'production',
output: {...},
plugins: [...],
optimization: {
'minimize': true,
minimizer: [new TerserPlugin({
terserOptions: {
compress: {
pure_funcs: [
'console.log',
'console.info',
'console.debug',
'console.warn'
]
}
}
})],
},
module: {...}
}];
};