From b045842ba269f0539f3327e947e40f521fa86207 Mon Sep 17 00:00:00 2001 From: Haz Date: Thu, 9 Jan 2020 18:59:37 -0300 Subject: [PATCH] Improve README with information about dead code removal --- packages/warning/README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/warning/README.md b/packages/warning/README.md index 053465f033692f..684dbaf37f41bf 100644 --- a/packages/warning/README.md +++ b/packages/warning/README.md @@ -14,7 +14,17 @@ _This package assumes that your code will run in an **ES2015+** environment. If ## Reducing bundle size -Literal strings aren't minified. Keeping them in your production bundle may increase the bundle size significantly. To prevent that, you can put `@wordpress/warning/babel-plugin` into your [babel config](https://babeljs.io/docs/en/plugins#plugin-options) or use [`@wordpress/babel-preset-default`](https://www.npmjs.com/package/@wordpress/babel-preset-default), which already includes the babel plugin. +Literal strings aren't minified. Keeping them in your production bundle may increase the bundle size significantly. + +To prevent that, you should: + +1. Put `@wordpress/warning/babel-plugin` into your [babel config](https://babeljs.io/docs/en/plugins#plugin-options) or use [`@wordpress/babel-preset-default`](https://www.npmjs.com/package/@wordpress/babel-preset-default), which already includes the babel plugin. + + This will make sure your `warning` calls are wrapped within a condition that checks if `process.env.NODE_ENV !== 'production'`. + +2. Use [UglifyJS](https://github.com/mishoo/UglifyJS2), [Terser](https://github.com/terser/terser) or any other JavaScript parser that performs [dead code elimination](https://en.wikipedia.org/wiki/Dead_code_elimination). This is usually used in conjunction with JavaScript bundlers, such as [webpack](https://github.com/webpack/webpack). + + When parsing the code in `production` mode, the `warning` call will be removed altogether. ## API