Strip console logs from production builds
See original GitHub issueProposal: Automatically remove console.log
statements from production builds while still keeping them in development builds.
Reasoning: Log statements can be useful to keep in development builds. However, they can be unnecessary and potentially sensitive to include in production builds. Currently, CRA does nothing with console logs, so if you want to have log messages in development, they must be manually removed for a production build.
Potential Solutions: There is a webpack loader that can strip aritrary code including console logs https://github.com/yahoo/strip-loader. We could also update our use UglifyJsPlugin
and provide the drop_console
option to the compressor.
Downsides: Anytime code is removed from builds weird situations can arise. Particularly bad would be unintentional side effects inside of a console log statement, which would be removed only in production and may lead to hard to debug problems. Additionally, there may be times where you deliberately want to include specific log messages in production. We would then have to support a way to flag certain console log lines to not be stripped.
I wanted to open the discussion because I couldn’t find any prior issues about this feature.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:4
- Comments:12 (2 by maintainers)
Top GitHub Comments
Sorry to comment on a closed issue, but what about only stripping
console.debug
? I agree thatlog
,warn
anderror
should remain, though.@tbillington you are absolutely right, this is my mistake best address for this is react-native-cli 😃 sorry for an opinionated discussion