You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Remove console.log calls from production build #1491
I know this is not what this issue is about, but if you're only looking for a way to prevent the console messages from showing up in the production build, but don't mind that the code staying as is (meaning it won't be stripped out of your production code), then you could just monkey-patch console.log() so that it only works in development.
Or a more elegant way of doing it would be using the debug module, which lets you display messages based on the name of the module calling it. This requires you to add a field to your localStorage as described here. You can simply not add this field for production and the debug messages won't show. I ended up creating a utility class to generate color-coded messages of different levels such as 'trace', 'info', 'warn', 'error', etc. The module name I passed was simply the name of my app, so I just needed to add this in my index.js:
@parkerdan that's not a bad solution tbh, but it also probably depends on what you're doing.
If someone wanted to be malicious and scan your code for key pieces of data that you use to debug with (i.e. user data, account data..), that'll still leak into the final output and may be found by searching for "console.".
You could probably obfuscate usage of console by renaming it, and the methods, and then hooking them up to noop functions. Again, it prob depends on what you're trying to protect / hide.
Activity
gaearon commentedon Feb 6, 2017
No, it’s not supported. You’d need to eject to do this automatically.
lany9527 commentedon Sep 29, 2017
you can find answer in this page:
https://stackoverflow.com/questions/41040266/remove-console-logs-with-webpack-uglify
glocore commentedon Jan 29, 2018
I know this is not what this issue is about, but if you're only looking for a way to prevent the console messages from showing up in the production build, but don't mind that the code staying as is (meaning it won't be stripped out of your production code), then you could just monkey-patch
console.log()so that it only works in development.Or a more elegant way of doing it would be using the debug module, which lets you display messages based on the name of the module calling it. This requires you to add a field to your localStorage as described here. You can simply not add this field for production and the debug messages won't show. I ended up creating a utility class to generate color-coded messages of different levels such as 'trace', 'info', 'warn', 'error', etc. The module name I passed was simply the name of my app, so I just needed to add this in my index.js:
parkerdan commentedon Feb 7, 2018
I have disabled in prod by adding this at the root index.
Is this a bad approach??
barbagallo commentedon Feb 27, 2018
@parkerdan that's not a bad solution tbh, but it also probably depends on what you're doing.
If someone wanted to be malicious and scan your code for key pieces of data that you use to debug with (i.e. user data, account data..), that'll still leak into the final output and may be found by searching for "console.".
You could probably obfuscate usage of
consoleby renaming it, and the methods, and then hooking them up to noop functions. Again, it prob depends on what you're trying to protect / hide.Or you could use something like this: https://www.npmjs.com/package/webpack-strip
behnammodi commentedon Jul 2, 2018
@gaearon Do you plan to add this item?