Skip to content

Commit

Permalink
Improve README with information about dead code removal
Browse files Browse the repository at this point in the history
  • Loading branch information
diegohaz committed Jan 9, 2020
1 parent aa2d200 commit b045842
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/warning/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit b045842

Please sign in to comment.