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 not mentioned in documentation.
I am initializing uglify from webpack like this: new webpack.optimize.UglifyJsPlugin()
My understanding is that I can use standalone Uglify lib to get all the options, but I don't know which one?
The problem is that drop_console
isn't working.
Try drop_console:
Update: For webpack v4 it has changed a little:
For uglifyjs-webpack-plugin, wrap options inside an uglifyOptions object:
I have added a comprehensive answer for webpack v4 with debug configuration
My scripts in package.json are like so:
this is what I've done to remove alert() and console.log() from my codes. global_defs => replace alerts with console.log then drop_console removes all console.logs and now nothing shows up in my browser console
plugin versions:
Right now uglifyjs-webpack-plugin v1.2.6 has been released and I used latest documentations for this one, So I suppose there wont be any problem with latest plugin too.
With
UglifyJsPlugin
we can handle comments, warnings, console logs but it will not be a good idea to remove all these in development mode. First check whether you are runningwebpack
forprov env or dev env
, if it isprod env
then you can remove all these, like this:Reference: https://github.com/mishoo/UglifyJS2#compressor-options
This is the new syntax for Webpack v4: