From 2300f9e9830b6bd04df253afc8121893789089ec Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Tue, 18 Sep 2018 14:31:02 -0400 Subject: [PATCH] Switch from uglifyjs to terser (#5026) Uglify is no longer maintained and has bugs not present in Terser (its successor) --- packages/react-dev-utils/printBuildError.js | 4 ++-- packages/react-error-overlay/package.json | 2 +- packages/react-error-overlay/webpack.config.iframe.js | 6 +++--- packages/react-scripts/config/webpack.config.prod.js | 8 ++++---- packages/react-scripts/package.json | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/react-dev-utils/printBuildError.js b/packages/react-dev-utils/printBuildError.js index 0fe7aa9a552..1e70b4e64f4 100644 --- a/packages/react-dev-utils/printBuildError.js +++ b/packages/react-dev-utils/printBuildError.js @@ -13,11 +13,11 @@ module.exports = function printBuildError(err) { const message = err != null && err.message; const stack = err != null && err.stack; - // Add more helpful message for UglifyJs error + // Add more helpful message for Terser error if ( stack && typeof message === 'string' && - message.indexOf('from UglifyJs') !== -1 + message.indexOf('from Terser') !== -1 ) { try { const matched = /(.+)\[(.+):(.+),(.+)\]\[.+\]/.exec(stack); diff --git a/packages/react-error-overlay/package.json b/packages/react-error-overlay/package.json index 78f11363e98..abd51987ac2 100644 --- a/packages/react-error-overlay/package.json +++ b/packages/react-error-overlay/package.json @@ -60,7 +60,7 @@ "rimraf": "^2.6.2", "settle-promise": "1.0.0", "source-map": "0.5.6", - "uglifyjs-webpack-plugin": "1.2.5", + "terser-webpack-plugin": "1.1.0", "webpack": "^4.8.1" }, "jest": { diff --git a/packages/react-error-overlay/webpack.config.iframe.js b/packages/react-error-overlay/webpack.config.iframe.js index 3a806f362db..67157bad440 100644 --- a/packages/react-error-overlay/webpack.config.iframe.js +++ b/packages/react-error-overlay/webpack.config.iframe.js @@ -8,7 +8,7 @@ const path = require('path'); const webpack = require('webpack'); -const UglifyJsPlugin = require('uglifyjs-webpack-plugin'); +const TerserPlugin = require('terser-webpack-plugin'); module.exports = { mode: process.env.NODE_ENV === 'production' ? 'production' : 'development', @@ -49,8 +49,8 @@ module.exports = { minimizer: [ // This code is embedded as a string, so it would never be optimized // elsewhere. - new UglifyJsPlugin({ - uglifyOptions: { + new TerserPlugin({ + terserOptions: { compress: { warnings: false, comparisons: false, diff --git a/packages/react-scripts/config/webpack.config.prod.js b/packages/react-scripts/config/webpack.config.prod.js index 34a437afce9..5d92c9ef859 100644 --- a/packages/react-scripts/config/webpack.config.prod.js +++ b/packages/react-scripts/config/webpack.config.prod.js @@ -12,7 +12,7 @@ const autoprefixer = require('autoprefixer'); const path = require('path'); const webpack = require('webpack'); const HtmlWebpackPlugin = require('html-webpack-plugin'); -const UglifyJsPlugin = require('uglifyjs-webpack-plugin'); +const TerserPlugin = require('terser-webpack-plugin'); const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin'); const ManifestPlugin = require('webpack-manifest-plugin'); @@ -115,10 +115,10 @@ module.exports = { }, optimization: { minimizer: [ - new UglifyJsPlugin({ - uglifyOptions: { + new TerserPlugin({ + terserOptions: { parse: { - // we want uglify-js to parse ecma 8 code. However, we don't want it + // we want terser to parse ecma 8 code. However, we don't want it // to apply any minfication steps that turns valid ecma 5 code // into invalid ecma 5 code. This is why the 'compress' and 'output' // sections only apply transformations that are ecma 5 safe diff --git a/packages/react-scripts/package.json b/packages/react-scripts/package.json index 2b444c0bded..0e639a768dd 100644 --- a/packages/react-scripts/package.json +++ b/packages/react-scripts/package.json @@ -64,8 +64,8 @@ "style-loader": "0.21.0", "svgr": "1.9.2", "sw-precache-webpack-plugin": "0.11.5", + "terser-webpack-plugin": "1.1.0", "thread-loader": "1.2.0", - "uglifyjs-webpack-plugin": "1.2.5", "url-loader": "1.0.1", "webpack": "4.19.0", "webpack-dev-server": "3.1.7",