Skip to content

Commit c024001

Browse files
Sibirajlex111
Sibiraj
andcommitted
Update Production Optimization docs to use terser (#2112)
* Update Production Optimization docs to use terser * Update Optimizing Performance.md * Fix typo Co-Authored-By: Alexey Pyltsyn <lex61rus@gmail.com>
1 parent d47597f commit c024001

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

content/docs/optimizing-performance.md

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ Remember that only React files ending with `.production.min.js` are suitable for
5151

5252
### Brunch {#brunch}
5353

54-
For the most efficient Brunch production build, install the [`uglify-js-brunch`](https://github.com/brunch/uglify-js-brunch) plugin:
54+
For the most efficient Brunch production build, install the [`terser-brunch`](https://github.com/brunch/terser-brunch) plugin:
5555

5656
```
5757
# If you use npm
58-
npm install --save-dev uglify-js-brunch
58+
npm install --save-dev terser-brunch
5959
6060
# If you use Yarn
61-
yarn add --dev uglify-js-brunch
61+
yarn add --dev terser-brunch
6262
```
6363

6464
Then, to create a production build, add the `-p` flag to the `build` command:
@@ -75,51 +75,46 @@ For the most efficient Browserify production build, install a few plugins:
7575

7676
```
7777
# If you use npm
78-
npm install --save-dev envify uglify-js uglifyify
78+
npm install --save-dev envify terser uglifyify
7979
8080
# If you use Yarn
81-
yarn add --dev envify uglify-js uglifyify
81+
yarn add --dev envify terser uglifyify
8282
```
8383

8484
To create a production build, make sure that you add these transforms **(the order matters)**:
8585

8686
* The [`envify`](https://github.com/hughsk/envify) transform ensures the right build environment is set. Make it global (`-g`).
8787
* The [`uglifyify`](https://github.com/hughsk/uglifyify) transform removes development imports. Make it global too (`-g`).
88-
* Finally, the resulting bundle is piped to [`uglify-js`](https://github.com/mishoo/UglifyJS2) for mangling ([read why](https://github.com/hughsk/uglifyify#motivationusage)).
88+
* Finally, the resulting bundle is piped to [`terser`](https://github.com/terser-js/terser) for mangling ([read why](https://github.com/hughsk/uglifyify#motivationusage)).
8989

9090
For example:
9191

9292
```
9393
browserify ./index.js \
9494
-g [ envify --NODE_ENV production ] \
9595
-g uglifyify \
96-
| uglifyjs --compress --mangle > ./bundle.js
96+
| terser --compress --mangle > ./bundle.js
9797
```
9898

99-
>**Note:**
100-
>
101-
>The package name is `uglify-js`, but the binary it provides is called `uglifyjs`.<br>
102-
>This is not a typo.
103-
10499
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.
105100

106101
### Rollup {#rollup}
107102

108103
For the most efficient Rollup production build, install a few plugins:
109104

110-
```
105+
```bash
111106
# If you use npm
112-
npm install --save-dev rollup-plugin-commonjs rollup-plugin-replace rollup-plugin-uglify
107+
npm install --save-dev rollup-plugin-commonjs rollup-plugin-replace rollup-plugin-terser
113108

114109
# If you use Yarn
115-
yarn add --dev rollup-plugin-commonjs rollup-plugin-replace rollup-plugin-uglify
110+
yarn add --dev rollup-plugin-commonjs rollup-plugin-replace rollup-plugin-terser
116111
```
117112

118113
To create a production build, make sure that you add these plugins **(the order matters)**:
119114

120115
* The [`replace`](https://github.com/rollup/rollup-plugin-replace) plugin ensures the right build environment is set.
121116
* The [`commonjs`](https://github.com/rollup/rollup-plugin-commonjs) plugin provides support for CommonJS in Rollup.
122-
* The [`uglify`](https://github.com/TrySound/rollup-plugin-uglify) plugin compresses and mangles the final bundle.
117+
* The [`terser`](https://github.com/TrySound/rollup-plugin-terser) plugin compresses and mangles the final bundle.
123118

124119
```js
125120
plugins: [
@@ -128,14 +123,14 @@ plugins: [
128123
'process.env.NODE_ENV': JSON.stringify('production')
129124
}),
130125
require('rollup-plugin-commonjs')(),
131-
require('rollup-plugin-uglify')(),
126+
require('rollup-plugin-terser')(),
132127
// ...
133128
]
134129
```
135130

136131
For a complete setup example [see this gist](https://gist.github.com/Rich-Harris/cb14f4bc0670c47d00d191565be36bf0).
137132

138-
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.
133+
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.
139134

140135
### webpack {#webpack}
141136

@@ -144,18 +139,22 @@ Remember that you only need to do this for production builds. You shouldn't appl
144139
>If you're using Create React App, please follow [the instructions above](#create-react-app).<br>
145140
>This section is only relevant if you configure webpack directly.
146141
147-
For the most efficient webpack production build, make sure to include these plugins in your production configuration:
142+
Webpack v4+ will minify your code by default in production mode.
148143

149144
```js
150-
new webpack.DefinePlugin({
151-
'process.env.NODE_ENV': JSON.stringify('production')
152-
}),
153-
new webpack.optimize.UglifyJsPlugin()
145+
const TerserPlugin = require('terser-webpack-plugin');
146+
147+
module.exports = {
148+
mode: 'production'
149+
optimization: {
150+
minimizer: [new TerserPlugin({ /* additional options here */ })],
151+
},
152+
};
154153
```
155154

156155
You can learn more about this in [webpack documentation](https://webpack.js.org/guides/production/).
157156

158-
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.
157+
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.
159158

160159
## Profiling Components with the Chrome Performance Tab {#profiling-components-with-the-chrome-performance-tab}
161160

0 commit comments

Comments
 (0)