Skip to content

Commit 311a728

Browse files
edmorleyvkrol
authored andcommitted
Switch from uglifyjs-webpack-plugin to terser-webpack-plugin
Some history: * `uglifyjs-webpack-plugin` < v1.0 used the minifier `uglify-js` * however `uglify-js` does not support ES6, which resulted in a fork called `uglify-es` that was developed in the `uglify-js` repository, but under the `harmony` branch * `uglifyjs-webpack-plugin` v1.x switched to `uglify-es` for ES6 support * however `uglify-es` stopped being maintained: mishoo/UglifyJS#3156 (comment) * which led to a fork called `terser` that has incorporated all of the unmerged PRs and will be where all new development occurs: https://github.com/fabiosantoscode/terser * `terser-webpack-plugin` was created, which is the `terser` equivalent of `uglifyjs-webpack-plugin`: https://github.com/webpack-contrib/terser-webpack-plugin * `uglifyjs-webpack-plugin` v2.x will be switching back to `uglify-js`, so any project that needs to support ES6 now needs to switch to `terser-webpack-plugin`. Fixes webpack#7923.
1 parent a230148 commit 311a728

File tree

13 files changed

+213
-198
lines changed

13 files changed

+213
-198
lines changed

benchmark/createBenchmark.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ webpack(
1515
},
1616
plugins: [
1717
new webpack.NamedModulesPlugin(),
18-
new webpack.IgnorePlugin(/^(fsevents|uglify-js)$/),
18+
new webpack.IgnorePlugin(/^(fsevents|terser)$/),
1919
new webpack.NormalModuleReplacementPlugin(
2020
/^.\/loadLoader$/,
2121
path.resolve(__dirname, "./createBenchmark/loadLoader")

examples/code-splitted-css-bundle/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ Child extract-text-webpack-plugin ../../node_modules/extract-text-webpack-plugin
101101
+ 1 hidden module
102102
```
103103

104-
## Minimized (uglify-js, no zip)
104+
## Minimized (terser, no zip)
105105

106106
```
107107
Hash: edbe0e91ba86d814d855

lib/WebpackOptionsDefaulter.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,10 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
302302
this.set("optimization.minimizer", "make", options => [
303303
{
304304
apply: compiler => {
305-
// Lazy load the uglifyjs plugin
306-
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
305+
// Lazy load the Terser plugin
306+
const TerserPlugin = require("terser-webpack-plugin");
307307
const SourceMapDevToolPlugin = require("./SourceMapDevToolPlugin");
308-
new UglifyJsPlugin({
308+
new TerserPlugin({
309309
cache: true,
310310
parallel: true,
311311
sourceMap:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"node-libs-browser": "^2.0.0",
2727
"schema-utils": "^0.4.4",
2828
"tapable": "^1.1.0",
29-
"uglifyjs-webpack-plugin": "^1.2.4",
29+
"terser-webpack-plugin": "^1.1.0",
3030
"watchpack": "^1.5.0",
3131
"webpack-sources": "^1.3.0"
3232
},

test/TestCases.template.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ const path = require("path");
55
const fs = require("fs");
66
const vm = require("vm");
77
const mkdirp = require("mkdirp");
8-
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
8+
const TerserPlugin = require("terser-webpack-plugin");
99
const checkArrayExpectation = require("./checkArrayExpectation");
1010
const createLazyTestEnv = require("./helpers/createLazyTestEnv");
1111

1212
const Stats = require("../lib/Stats");
1313
const webpack = require("../lib/webpack");
1414

15-
const uglifyJsForTesting = new UglifyJsPlugin({
15+
const terserForTesting = new TerserPlugin({
1616
cache: false,
1717
parallel: false,
1818
sourceMap: true
@@ -31,12 +31,12 @@ const DEFAULT_OPTIMIZATIONS = {
3131
concatenateModules: false,
3232
namedModules: false,
3333
hashedModuleIds: false,
34-
minimizer: [uglifyJsForTesting]
34+
minimizer: [terserForTesting]
3535
};
3636

3737
const NO_EMIT_ON_ERRORS_OPTIMIZATIONS = {
3838
noEmitOnErrors: false,
39-
minimizer: [uglifyJsForTesting]
39+
minimizer: [terserForTesting]
4040
};
4141

4242
const casesPath = path.join(__dirname, "cases");

test/__snapshots__/StatsTestCases.test.js.snap

Lines changed: 82 additions & 92 deletions
Large diffs are not rendered by default.

test/cases/parsing/optional-catch-binding/test.filter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const supportsOptionalCatchBinding = require("../../../helpers/supportsOptionalCatchBinding");
22

33
module.exports = function(config) {
4-
// XXX: Disable this test if UglifyJS is used because it does not support ES 2019
4+
// XXX: Disable this test if Terser is used because it does not support ES 2019
55
if (config.mode === "production") {
66
return false;
77
}

test/checkArrayExpectation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module.exports = function checkArrayExpectation(
1717
}
1818
let array = object[`${kind}s`].slice().sort();
1919
if (kind === "warning")
20-
array = array.filter(item => !/from UglifyJs/.test(item));
20+
array = array.filter(item => !/from Terser/.test(item));
2121
if (fs.existsSync(path.join(testDirectory, `${filename}.js`))) {
2222
const expectedFilename = path.join(testDirectory, `${filename}.js`);
2323
const expected = require(expectedFilename);

test/configCases/plugins/source-map-dev-tool-plugin/webpack.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var webpack = require("../../../../");
2-
var UglifyJsPlugin = require("uglifyjs-webpack-plugin");
2+
var TerserPlugin = require("terser-webpack-plugin");
33
module.exports = {
44
node: {
55
__dirname: false,
@@ -14,7 +14,7 @@ module.exports = {
1414
},
1515
optimization: {
1616
minimizer: [
17-
new UglifyJsPlugin({
17+
new TerserPlugin({
1818
sourceMap: true
1919
})
2020
]

test/configCases/plugins/uglifyjs-plugin/webpack.config.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
1+
const TerserPlugin = require("terser-webpack-plugin");
22
module.exports = {
33
node: {
44
__dirname: false,
@@ -17,21 +17,21 @@ module.exports = {
1717
optimization: {
1818
minimize: true,
1919
minimizer: [
20-
new UglifyJsPlugin({
20+
new TerserPlugin({
2121
cache: false,
2222
parallel: false,
2323
exclude: ["vendors.js", "extract.js"]
2424
}),
25-
new UglifyJsPlugin({
25+
new TerserPlugin({
2626
cache: false,
2727
parallel: false,
2828
extractComments: true,
2929
include: ["extract.js"]
3030
}),
31-
new UglifyJsPlugin({
31+
new TerserPlugin({
3232
cache: false,
3333
parallel: false,
34-
uglifyOptions: {
34+
terserOptions: {
3535
compress: {
3636
passes: 2
3737
}

0 commit comments

Comments
 (0)