Skip to content

Commit 57b4599

Browse files
vkrolEugeneHlushko
authored andcommitted
Replace UglifyJS with Terser (#2656) (#2658)
1 parent d05274c commit 57b4599

14 files changed

+25
-35
lines changed

src/content/api/cli.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ Parameter | Explanation
245245
--------------------------- | -------------------------------------------------------|----------------------
246246
`--optimize-max-chunks` | Try to keep the chunk count below a limit | [LimitChunkCountPlugin](/plugins/limit-chunk-count-plugin)
247247
`--optimize-min-chunk-size` | Try to keep the chunk size above a limit | [MinChunkSizePlugin](/plugins/min-chunk-size-plugin)
248-
`--optimize-minimize` | Minimize javascript and switches loaders to minimizing | [UglifyJsPlugin](/plugins/uglifyjs-webpack-plugin/) & [LoaderOptionsPlugin](/plugins/loader-options-plugin/)
248+
`--optimize-minimize` | Minimize javascript and switches loaders to minimizing | [TerserPlugin](/plugins/terser-webpack-plugin/) & [LoaderOptionsPlugin](/plugins/loader-options-plugin/)
249249

250250

251251
### Resolve Options

src/content/comparison.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ webpack is not the only module bundler out there. If you are choosing between us
3636
| Indirect require `var r = require; r("./file")` | __yes__ | no♦ | no | no | no | |
3737
| Load each file separate | no | yes | no | yes | no | no |
3838
| Mangle path names | __yes__ | no | partial | yes | not required (path names are not included in the bundle) | no |
39-
| Minimizing | uglify | uglify, closure compiler | [uglifyify](https://github.com/hughsk/uglifyify) | yes | [uglify-plugin](https://github.com/TrySound/rollup-plugin-uglify) | [UglifyJS-brunch](https://github.com/brunch/uglify-js-brunch)
39+
| Minimizing | terser | uglify, closure compiler | [uglifyify](https://github.com/hughsk/uglifyify) | yes | [uglify-plugin](https://github.com/TrySound/rollup-plugin-uglify) | [UglifyJS-brunch](https://github.com/brunch/uglify-js-brunch)
4040
| Multi pages build with common bundle | with manual configuration | __yes__ | with manual configuration | with bundle arithmetic | no | no|
4141
| Multiple bundles | __yes__ | with manual configuration | with manual configuration | yes | no | yes |
4242
| Node.js built-in libs `require("path")` | __yes__ | no | __yes__ | __yes__ | [node-resolve-plugin](https://github.com/rollup/rollup-plugin-node-resolve) | |

src/content/concepts/mode.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ The following string values are supported:
3939
Option | Description
4040
--------------------- | -----------------------
4141
`development` | Sets `process.env.NODE_ENV` on `DefinePlugin` to value `development`. Enables `NamedChunksPlugin` and `NamedModulesPlugin`.
42-
`production` | Sets `process.env.NODE_ENV` on `DefinePlugin` to value `production`. Enables `FlagDependencyUsagePlugin`, `FlagIncludedChunksPlugin`, `ModuleConcatenationPlugin`, `NoEmitOnErrorsPlugin`, `OccurrenceOrderPlugin`, `SideEffectsFlagPlugin` and `UglifyJsPlugin`.
42+
`production` | Sets `process.env.NODE_ENV` on `DefinePlugin` to value `production`. Enables `FlagDependencyUsagePlugin`, `FlagIncludedChunksPlugin`, `ModuleConcatenationPlugin`, `NoEmitOnErrorsPlugin`, `OccurrenceOrderPlugin`, `SideEffectsFlagPlugin` and `TerserPlugin`.
4343
`none` | Opts out of any default optimization options
4444

4545
If not set, webpack sets `production` as the default value for `mode`. The supported values for mode are:
@@ -123,7 +123,7 @@ module.exports = {
123123
- minimize: true,
124124
- },
125125
- plugins: [
126-
- new UglifyJsPlugin(/* ... */),
126+
- new TerserPlugin(/* ... */),
127127
- new webpack.DefinePlugin({ "process.env.NODE_ENV": JSON.stringify("production") }),
128128
- new webpack.optimize.ModuleConcatenationPlugin(),
129129
- new webpack.NoEmitOnErrorsPlugin()

src/content/configuration/configuration-languages.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ config =
120120
use: 'babel-loader'
121121
} ]
122122
plugins: [
123-
new (webpack.optimize.UglifyJsPlugin)
124123
new HtmlWebpackPlugin(template: './src/index.html')
125124
]
126125

@@ -169,10 +168,6 @@ export default (
169168
}} />
170169
</resolve>
171170
<plugins>
172-
<uglify-js opts={{
173-
compression: true,
174-
mangle: false
175-
}} />
176171
<CustomPlugin foo="bar" />
177172
</plugins>
178173
</webpack>

src/content/configuration/configuration-types.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ One option is to export a function from your webpack config instead of exporting
3131
+ mode: env.production ? 'production' : 'development',
3232
+ devtool: env.production ? 'source-maps' : 'eval',
3333
plugins: [
34-
new webpack.optimize.UglifyJsPlugin({
35-
+ compress: argv['optimize-minimize'] // only if -p or --optimize-minimize were passed
34+
new TerserPlugin({
35+
terserOptions: {
36+
+ compress: argv['optimize-minimize'] // only if -p or --optimize-minimize were passed
37+
}
3638
})
3739
]
3840
+ };

src/content/configuration/devtool.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,4 @@ W> You should not deploy the Source Map file to the webserver. Instead only use
114114

115115
W> It still exposes filenames and structure for decompiling, but it doesn't expose the original code.
116116

117-
T> When using the `uglifyjs-webpack-plugin` you must provide the `sourceMap: true` option to enable SourceMap support.
117+
T> When using the `terser-webpack-plugin` you must provide the `sourceMap: true` option to enable SourceMap support.

src/content/configuration/optimization.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Since version 4 webpack runs optimizations for you depending on the chosen [`mo
2020

2121
`boolean`
2222

23-
Tell webpack to minimize the bundle using the [UglifyjsWebpackPlugin](/plugins/uglifyjs-webpack-plugin/).
23+
Tell webpack to minimize the bundle using the [TerserPlugin](/plugins/terser-webpack-plugin/).
2424

2525
This is `true` by default in `production` mode.
2626

@@ -40,21 +40,21 @@ T> Learn how [mode](/concepts/mode/) works.
4040

4141
## `optimization.minimizer`
4242

43-
`[UglifyjsWebpackPlugin]`
43+
`[TerserPlugin]`
4444

45-
Allows you to override the default minimizer by providing a different one or more customized [UglifyjsWebpackPlugin](/plugins/uglifyjs-webpack-plugin/) instances.
45+
Allows you to override the default minimizer by providing a different one or more customized [TerserPlugin](/plugins/terser-webpack-plugin/) instances.
4646

4747
__webpack.config.js__
4848

4949

5050
```js
51-
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
51+
const TerserPlugin = require('terser-webpack-plugin');
5252

5353
module.exports = {
5454
//...
5555
optimization: {
5656
minimizer: [
57-
new UglifyJsPlugin({ /* your config */ })
57+
new TerserPlugin({ /* your config */ })
5858
]
5959
}
6060
};

src/content/guides/build-performance.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,9 @@ Be aware of the performance differences of the different `devtool` settings.
148148

149149
### Avoid Production Specific Tooling
150150

151-
Certain utilities, plugins, and loaders only make sense when building for production. For example, it usually doesn't make sense to minify and mangle your code with the `UglifyJsPlugin` while in development. These tools should typically be excluded in development:
151+
Certain utilities, plugins, and loaders only make sense when building for production. For example, it usually doesn't make sense to minify and mangle your code with the `TerserPlugin` while in development. These tools should typically be excluded in development:
152152

153-
- `UglifyJsPlugin`
153+
- `TerserPlugin`
154154
- `ExtractTextPlugin`
155155
- `[hash]`/`[chunkhash]`
156156
- `AggressiveSplittingPlugin`

src/content/guides/integrations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ contributors:
1010

1111
Let's start by clearing up a common misconception. webpack is a module bundler like [Browserify](http://browserify.org/) or [Brunch](http://brunch.io/). It is _not a task runner_ like [Make](https://www.gnu.org/software/make/), [Grunt](https://gruntjs.com/), or [Gulp](https://gulpjs.com/). Task runners handle automation of common development tasks such as linting, building, or testing your project. Compared to bundlers, task runners have a higher level focus. You can still benefit from their higher level tooling while leaving the problem of bundling to webpack.
1212

13-
Bundlers help you get your JavaScript and stylesheets ready for deployment, transforming them into a format that's suitable for the browser. For example, JavaScript can be [minified](/plugins/uglifyjs-webpack-plugin) or [split into chunks](/guides/code-splitting) and [lazy-loaded](/guides/lazy-loading) to improve performance. Bundling is one of the most important challenges in web development, and solving it well can remove a lot of pain from the process.
13+
Bundlers help you get your JavaScript and stylesheets ready for deployment, transforming them into a format that's suitable for the browser. For example, JavaScript can be [minified](/plugins/terser-webpack-plugin) or [split into chunks](/guides/code-splitting) and [lazy-loaded](/guides/lazy-loading) to improve performance. Bundling is one of the most important challenges in web development, and solving it well can remove a lot of pain from the process.
1414

1515
The good news is that, while there is some overlap, task runners and bundlers can play well together if approached in the right way. This guide provides a high-level overview of how webpack can be integrated into some of the more popular task runners.
1616

src/content/guides/production.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ __webpack.prod.js__
102102
+ });
103103
```
104104

105-
In `webpack.common.js`, we now have setup our `entry` and `output` configuration and we've included any plugins that are required for both environments. In `webpack.dev.js`, we've set ``mode`` to ``development``. Also, we've added the recommended `devtool` for that environment (strong source mapping), as well as our simple `devServer` configuration. Finally, in `webpack.prod.js`,``mode`` is set to ``production`` which loads `UglifyJSPlugin` which was first introduced by the [tree shaking](/guides/tree-shaking) guide.
105+
In `webpack.common.js`, we now have setup our `entry` and `output` configuration and we've included any plugins that are required for both environments. In `webpack.dev.js`, we've set ``mode`` to ``development``. Also, we've added the recommended `devtool` for that environment (strong source mapping), as well as our simple `devServer` configuration. Finally, in `webpack.prod.js`,``mode`` is set to ``production`` which loads `TerserPlugin` which was first introduced by the [tree shaking](/guides/tree-shaking) guide.
106106

107107
Note the use of `merge()` in the environment-specific configurations to easily include our common configuration in `dev` and `prod`. The `webpack-merge` tool offers a variety of advanced features for merging but for our use case we won't need any of that.
108108

@@ -195,7 +195,7 @@ __src/index.js__
195195

196196
webpack v4+ will minify your code by default in [`production mode`](/concepts/mode/#mode-production).
197197

198-
Note that while the [`UglifyJSPlugin`](/plugins/uglifyjs-webpack-plugin) is a great place to start for minification and being used by default, there are other options out there. Here are a few more popular ones:
198+
Note that while the [`TerserPlugin`](/plugins/terser-webpack-plugin) is a great place to start for minification and being used by default, there are other options out there. Here are a few more popular ones:
199199

200200
- [`BabelMinifyWebpackPlugin`](https://github.com/webpack-contrib/babel-minify-webpack-plugin)
201201
- [`ClosureCompilerPlugin`](https://github.com/roman01la/webpack-closure-compiler)
@@ -229,6 +229,6 @@ It is crucial to minimize your CSS on production, please see [Minimizing for Pro
229229

230230
## CLI Alternatives
231231

232-
Some of what has been described above is also achievable via the command line. For example, the `--optimize-minimize` flag will include the `UglifyJSPlugin` behind the scenes. The `--define process.env.NODE_ENV="'production'"` will do the same for the `DefinePlugin` instance described above. And, `webpack -p` will automatically invoke both those flags and thus the plugins to be included.
232+
Some of what has been described above is also achievable via the command line. For example, the `--optimize-minimize` flag will include the `TerserPlugin` behind the scenes. The `--define process.env.NODE_ENV="'production'"` will do the same for the `DefinePlugin` instance described above. And, `webpack -p` will automatically invoke both those flags and thus the plugins to be included.
233233

234234
While these short hand methods are nice, we usually recommend just using the configuration as it's better to understand exactly what is being done for you in both cases. The configuration also gives you more control on fine tuning other options within both plugins.

0 commit comments

Comments
 (0)