Nopzen
Nopzen

Reputation: 576

Uglify JS - remove only console.log

I have a question regarding the Uglify JS module, in the usecase of webpack plugin.

My codebase have several console.log statements around the code for debugging purposes localy, it will only be printede out in development mode, but they are still taking up space in the codebase and i dont what them in the production build but, i would like to keep my console.error and console.warn still.

I know the Uglify JS have key drop_console flag but that kills every console output there is and i still want the warnings and errors in my console.

The reason for this question is i have a custom error handler than ships errors to Sentry, and I want to read the error in the console when it happens, so i use the error and warning console out put.

Upvotes: 2

Views: 1581

Answers (1)

barbsan
barbsan

Reputation: 3458

From docs:

drop_console (default: false) -- Pass true to discard calls to console.* functions. If you wish to drop a specific function call such as console.info and/or retain side effects from function arguments after dropping the function call then use pure_funcs instead.

...

pure_funcs (default: null) -- [...] You can pass pure_funcs: [ 'Math.floor' ] to let it know that this function won't produce any side effect, in which case the whole statement would get discarded.

So the option you're looking for is pure_funcs: [ 'console.log' ]

Upvotes: 4

Related Questions