@ -51,14 +51,14 @@ Remember that only React files ending with `.production.min.js` are suitable for
### Brunch {#brunch}
### Brunch {#brunch}
For the most efficient Brunch production build, install the [`uglify-js-brunch`](https://github.com/brunch/uglify-js-brunch) plugin:
For the most efficient Brunch production build, install the [`terser-brunch`](https://github.com/brunch/terser-brunch) plugin:
```
```
# If you use npm
# If you use npm
npm install --save-dev uglify-js-brunch
npm install --save-dev terser-brunch
# If you use Yarn
# If you use Yarn
yarn add --dev uglify-js-brunch
yarn add --dev terser-brunch
```
```
Then, to create a production build, add the `-p` flag to the `build` command:
Then, to create a production build, add the `-p` flag to the `build` command:
@ -75,17 +75,17 @@ For the most efficient Browserify production build, install a few plugins:
```
```
# If you use npm
# If you use npm
npm install --save-dev envify uglify-js uglifyify
npm install --save-dev envify terser uglifyify
# If you use Yarn
# If you use Yarn
yarn add --dev envify uglify-js uglifyify
yarn add --dev envify terser uglifyify
```
```
To create a production build, make sure that you add these transforms **(the order matters)**:
To create a production build, make sure that you add these transforms **(the order matters)**:
* The [`envify`](https://github.com/hughsk/envify) transform ensures the right build environment is set. Make it global (`-g`).
* The [`envify`](https://github.com/hughsk/envify) transform ensures the right build environment is set. Make it global (`-g`).
* The [`uglifyify`](https://github.com/hughsk/uglifyify) transform removes development imports. Make it global too (`-g`).
* The [`uglifyify`](https://github.com/hughsk/uglifyify) transform removes development imports. Make it global too (`-g`).
* Finally, the resulting bundle is piped to [`uglify-js`](https://github.com/mishoo/UglifyJS2) for mangling ([read why](https://github.com/hughsk/uglifyify#motivationusage)).
* Finally, the resulting bundle is piped to [`terser`](https://github.com/terser-js/terser) for mangling ([read why](https://github.com/hughsk/uglifyify#motivationusage)).
For example:
For example:
@ -93,33 +93,28 @@ For example:
browserify ./index.js \
browserify ./index.js \
-g [ envify --NODE_ENV production ] \
-g [ envify --NODE_ENV production ] \
-g uglifyify \
-g uglifyify \
| uglifyjs --compress --mangle > ./bundle.js
| terser --compress --mangle > ./bundle.js
```
```
>**Note:**
>
>The package name is `uglify-js`, but the binary it provides is called `uglifyjs`.<br>
>This is not a typo.
Remember that you only need to do this for production builds. You shouldn't apply these plugins in development because they will hide useful React warnings, and make the builds much slower.
Remember that you only need to do this for production builds. You shouldn't apply these plugins in development because they will hide useful React warnings, and make the builds much slower.
### Rollup {#rollup}
### Rollup {#rollup}
For the most efficient Rollup production build, install a few plugins:
For the most efficient Rollup production build, install a few plugins:
For a complete setup example [see this gist](https://gist.github.com/Rich-Harris/cb14f4bc0670c47d00d191565be36bf0).
For a complete setup example [see this gist](https://gist.github.com/Rich-Harris/cb14f4bc0670c47d00d191565be36bf0).
Remember that you only need to do this for production builds. You shouldn't apply the `uglify` plugin or the `replace` plugin with `'production'` value in development because they will hide useful React warnings, and make the builds much slower.
Remember that you only need to do this for production builds. You shouldn't apply the `terser` plugin or the `replace` plugin with `'production'` value in development because they will hide useful React warnings, and make the builds much slower.
### webpack {#webpack}
### webpack {#webpack}
@ -144,18 +139,22 @@ Remember that you only need to do this for production builds. You shouldn't appl
minimizer: [new TerserPlugin({ /* additional options here */ })],
},
};
```
```
You can learn more about this in [webpack documentation](https://webpack.js.org/guides/production/).
You can learn more about this in [webpack documentation](https://webpack.js.org/guides/production/).
Remember that you only need to do this for production builds. You shouldn't apply `UglifyJsPlugin` or `DefinePlugin` with `'production'` value in development because they will hide useful React warnings, and make the builds much slower.
Remember that you only need to do this for production builds. You shouldn't apply `TerserPlugin` in development because it will hide useful React warnings, and make the builds much slower.
## Profiling Components with the Chrome Performance Tab {#profiling-components-with-the-chrome-performance-tab}
## Profiling Components with the Chrome Performance Tab {#profiling-components-with-the-chrome-performance-tab}