Skip to content

Commit 270fd62

Browse files
committed
Conditionally drop console messages from production build
Add a environment variable, `DROP_CONSOLE`, to specify if console function calls should be dropped in the production build.
1 parent 6223fd9 commit 270fd62

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

β€Ždocusaurus/docs/advanced-configuration.mdβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ You can adjust various development and production settings by setting environmen
2424
| GENERATE_SOURCEMAP | 🚫 Ignored | βœ… Used | When set to `false`, source maps are not generated for a production build. This solves out of memory (OOM) issues on some smaller machines. |
2525
| INLINE_RUNTIME_CHUNK | 🚫 Ignored | βœ… Used | By default, Create React App will embed the runtime script into `index.html` during the production build. When set to `false`, the script will not be embedded and will be imported as usual. This is normally required when dealing with CSP. |
2626
| IMAGE_INLINE_SIZE_LIMIT | 🚫 Ignored | βœ… Used | By default, images smaller than 10,000 bytes are encoded as a data URI in base64 and inlined in the CSS or JS build artifact. Set this to control the size limit in bytes. Setting it to 0 will disable the inlining of images. |
27+
| DROP_CONSOLE | 🚫 Ignored | βœ… Used | When set to `true`, `console.*` functions during the production build will be dropped. When set to `false`, the default, these function calls will be included as usual. |
2728
| EXTEND_ESLINT | βœ… Used | βœ… Used | When set to `true`, user provided ESLint configs will be used by `eslint-loader`. Note that any rules set to `"error"` will stop the application from building. |
2829
| FAST_REFRESH | βœ… Used | 🚫 Ignored | When set to `true`, enables experimental support for fast refresh to allow you to tweak your components in real time without reloading the page. |
2930
| TSC_COMPILE_ON_ERROR | βœ… Used | βœ… Used | When set to `true`, you can run and properly build TypeScript projects even if there are TypeScript type check errors. These errors are printed as warnings in the terminal and/or browser console. |

β€Žpackages/react-scripts/config/webpack.config.jsβ€Ž

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ const imageInlineSizeLimit = parseInt(
5757
process.env.IMAGE_INLINE_SIZE_LIMIT || '10000'
5858
);
5959

60+
const shouldDropConsole = process.env.DROP_CONSOLE === 'true';
61+
6062
// Check if TypeScript is setup
6163
const useTypeScript = fs.existsSync(paths.appTsConfig);
6264

@@ -233,6 +235,7 @@ module.exports = function (webpackEnv) {
233235
ecma: 8,
234236
},
235237
compress: {
238+
drop_console: shouldDropConsole,
236239
ecma: 5,
237240
warnings: false,
238241
// Disabled because of an issue with Uglify breaking seemingly valid code:

0 commit comments

Comments
Β (0)