From 1aa4dce7f75a2ccd2c9fe1f071f5dfd359e83ace Mon Sep 17 00:00:00 2001 From: igor-dv Date: Fri, 23 Nov 2018 22:01:41 +0200 Subject: [PATCH 1/4] Do not use UglifyJsPlugin for production --- lib/core/src/server/preview/iframe-webpack.config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/core/src/server/preview/iframe-webpack.config.js b/lib/core/src/server/preview/iframe-webpack.config.js index b1408691f83..1a5832c60dc 100644 --- a/lib/core/src/server/preview/iframe-webpack.config.js +++ b/lib/core/src/server/preview/iframe-webpack.config.js @@ -95,6 +95,7 @@ export default ({ chunks: 'all', }, runtimeChunk: true, + minimize: false, }, performance: { hints: isProd ? 'warning' : false, From a19a2bcdf5572654bd7976691d87c0c67869a21e Mon Sep 17 00:00:00 2001 From: igor-dv Date: Fri, 23 Nov 2018 23:27:56 +0200 Subject: [PATCH 2/4] We should use UglifyJsPlugin on a producion build but without mangling --- lib/core/package.json | 1 + .../server/preview/iframe-webpack.config.js | 10 +++++- yarn.lock | 36 ++++++++++++++++++- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/lib/core/package.json b/lib/core/package.json index fb44097e774..89f16a5f4ad 100644 --- a/lib/core/package.json +++ b/lib/core/package.json @@ -81,6 +81,7 @@ "spawn-promise": "^0.1.8", "style-loader": "^0.23.1", "svg-url-loader": "^2.3.2", + "uglifyjs-webpack-plugin": "^2.0.1", "url-loader": "^1.1.2", "webpack": "^4.23.1", "webpack-dev-middleware": "^3.4.0", diff --git a/lib/core/src/server/preview/iframe-webpack.config.js b/lib/core/src/server/preview/iframe-webpack.config.js index 1a5832c60dc..31f59427801 100644 --- a/lib/core/src/server/preview/iframe-webpack.config.js +++ b/lib/core/src/server/preview/iframe-webpack.config.js @@ -4,6 +4,7 @@ import Dotenv from 'dotenv-webpack'; import HtmlWebpackPlugin from 'html-webpack-plugin'; import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin'; import WatchMissingNodeModulesPlugin from 'react-dev-utils/WatchMissingNodeModulesPlugin'; +import UglifyJsPlugin from 'uglifyjs-webpack-plugin'; import { includePaths, @@ -95,7 +96,14 @@ export default ({ chunks: 'all', }, runtimeChunk: true, - minimize: false, + minimize: isProd, + minimizer: [ + new UglifyJsPlugin({ + uglifyOptions: { + mangle: false, + }, + }), + ], }, performance: { hints: isProd ? 'warning' : false, diff --git a/yarn.lock b/yarn.lock index 5afff4b9a41..0039fc75d22 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5691,6 +5691,26 @@ cacache@^11.0.1, cacache@^11.0.2: unique-filename "^1.1.0" y18n "^4.0.0" +cacache@^11.2.0: + version "11.3.1" + resolved "https://registry.yarnpkg.com/cacache/-/cacache-11.3.1.tgz#d09d25f6c4aca7a6d305d141ae332613aa1d515f" + integrity sha512-2PEw4cRRDu+iQvBTTuttQifacYjLPhET+SYO/gEFMy8uhi+jlJREDAjSF5FWSdV/Aw5h18caHA7vMTw2c+wDzA== + dependencies: + bluebird "^3.5.1" + chownr "^1.0.1" + figgy-pudding "^3.1.0" + glob "^7.1.2" + graceful-fs "^4.1.11" + lru-cache "^4.1.3" + mississippi "^3.0.0" + mkdirp "^0.5.1" + move-concurrently "^1.0.1" + promise-inflight "^1.0.1" + rimraf "^2.6.2" + ssri "^6.0.0" + unique-filename "^1.1.0" + y18n "^4.0.0" + cache-base@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/cache-base/-/cache-base-1.0.1.tgz#0a7f46416831c8b662ee36fe4e7c59d76f666ab2" @@ -21931,7 +21951,7 @@ uglify-es@^3.1.9, uglify-es@^3.3.4: commander "~2.13.0" source-map "~0.6.1" -uglify-js@3.4.x, uglify-js@^3.1.4, uglify-js@^3.4.0: +uglify-js@3.4.x, uglify-js@^3.0.0, uglify-js@^3.1.4, uglify-js@^3.4.0: version "3.4.9" resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.4.9.tgz#af02f180c1207d76432e473ed24a28f4a782bae3" integrity sha512-8CJsbKOtEbnJsTyv6LE6m6ZKniqMiFWmm9sRbopbkGs3gMPPfd3Fh8iIA4Ykv5MgaTbqHr4BaoGLJLZNhsrW1Q== @@ -21953,6 +21973,20 @@ uglifyjs-webpack-plugin@^1.2.4: webpack-sources "^1.1.0" worker-farm "^1.5.2" +uglifyjs-webpack-plugin@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/uglifyjs-webpack-plugin/-/uglifyjs-webpack-plugin-2.0.1.tgz#f346af53ed496ce72fef462517d417f62bec3010" + integrity sha512-1HhCHkOB6wRCcv7htcz1QRPVbWPEY074RP9vzt/X0LF4xXm9l4YGd0qja7z88abDixQlnVwBjXsTBs+Xsn/eeQ== + dependencies: + cacache "^11.2.0" + find-cache-dir "^2.0.0" + schema-utils "^1.0.0" + serialize-javascript "^1.4.0" + source-map "^0.6.1" + uglify-js "^3.0.0" + webpack-sources "^1.1.0" + worker-farm "^1.5.2" + uid-number@0.0.6: version "0.0.6" resolved "https://registry.yarnpkg.com/uid-number/-/uid-number-0.0.6.tgz#0ea10e8035e8eb5b8e4449f06da1c730663baa81" From f349feddcaf9c5ddd464d06e12747ec13e2214b6 Mon Sep 17 00:00:00 2001 From: igor-dv Date: Sat, 24 Nov 2018 00:51:24 +0200 Subject: [PATCH 3/4] Use "terser-webpack-plugin" instead of "uglifyjs-webpack-plugin" like webpack does https://github.com/webpack/webpack/blob/e1df721fd77634b5a22b4349c7d7ea15f0a2188e/lib/WebpackOptionsDefaulter.js#L306 --- lib/core/package.json | 2 +- .../server/preview/iframe-webpack.config.js | 9 +++-- yarn.lock | 38 +------------------ 3 files changed, 8 insertions(+), 41 deletions(-) diff --git a/lib/core/package.json b/lib/core/package.json index 89f16a5f4ad..a3bbb88a4e7 100644 --- a/lib/core/package.json +++ b/lib/core/package.json @@ -81,8 +81,8 @@ "spawn-promise": "^0.1.8", "style-loader": "^0.23.1", "svg-url-loader": "^2.3.2", - "uglifyjs-webpack-plugin": "^2.0.1", "url-loader": "^1.1.2", + "terser-webpack-plugin": "^1.1.0", "webpack": "^4.23.1", "webpack-dev-middleware": "^3.4.0", "webpack-hot-middleware": "^2.24.3" diff --git a/lib/core/src/server/preview/iframe-webpack.config.js b/lib/core/src/server/preview/iframe-webpack.config.js index 31f59427801..c08394ff5fb 100644 --- a/lib/core/src/server/preview/iframe-webpack.config.js +++ b/lib/core/src/server/preview/iframe-webpack.config.js @@ -4,7 +4,7 @@ import Dotenv from 'dotenv-webpack'; import HtmlWebpackPlugin from 'html-webpack-plugin'; import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin'; import WatchMissingNodeModulesPlugin from 'react-dev-utils/WatchMissingNodeModulesPlugin'; -import UglifyJsPlugin from 'uglifyjs-webpack-plugin'; +import TerserWebpackPlugin from 'terser-webpack-plugin'; import { includePaths, @@ -96,10 +96,11 @@ export default ({ chunks: 'all', }, runtimeChunk: true, - minimize: isProd, minimizer: [ - new UglifyJsPlugin({ - uglifyOptions: { + new TerserWebpackPlugin({ + cache: true, + parallel: true, + terserOptions: { mangle: false, }, }), diff --git a/yarn.lock b/yarn.lock index 0039fc75d22..0a95f611d20 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5691,26 +5691,6 @@ cacache@^11.0.1, cacache@^11.0.2: unique-filename "^1.1.0" y18n "^4.0.0" -cacache@^11.2.0: - version "11.3.1" - resolved "https://registry.yarnpkg.com/cacache/-/cacache-11.3.1.tgz#d09d25f6c4aca7a6d305d141ae332613aa1d515f" - integrity sha512-2PEw4cRRDu+iQvBTTuttQifacYjLPhET+SYO/gEFMy8uhi+jlJREDAjSF5FWSdV/Aw5h18caHA7vMTw2c+wDzA== - dependencies: - bluebird "^3.5.1" - chownr "^1.0.1" - figgy-pudding "^3.1.0" - glob "^7.1.2" - graceful-fs "^4.1.11" - lru-cache "^4.1.3" - mississippi "^3.0.0" - mkdirp "^0.5.1" - move-concurrently "^1.0.1" - promise-inflight "^1.0.1" - rimraf "^2.6.2" - ssri "^6.0.0" - unique-filename "^1.1.0" - y18n "^4.0.0" - cache-base@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/cache-base/-/cache-base-1.0.1.tgz#0a7f46416831c8b662ee36fe4e7c59d76f666ab2" @@ -21390,7 +21370,7 @@ term-size@^1.2.0: dependencies: execa "^0.7.0" -terser-webpack-plugin@1.1.0: +terser-webpack-plugin@1.1.0, terser-webpack-plugin@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/terser-webpack-plugin/-/terser-webpack-plugin-1.1.0.tgz#cf7c25a1eee25bf121f4a587bb9e004e3f80e528" integrity sha512-61lV0DSxMAZ8AyZG7/A4a3UPlrbOBo8NIQ4tJzLPAdGOQ+yoNC7l5ijEow27lBAL2humer01KLS6bGIMYQxKoA== @@ -21951,7 +21931,7 @@ uglify-es@^3.1.9, uglify-es@^3.3.4: commander "~2.13.0" source-map "~0.6.1" -uglify-js@3.4.x, uglify-js@^3.0.0, uglify-js@^3.1.4, uglify-js@^3.4.0: +uglify-js@3.4.x, uglify-js@^3.1.4, uglify-js@^3.4.0: version "3.4.9" resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.4.9.tgz#af02f180c1207d76432e473ed24a28f4a782bae3" integrity sha512-8CJsbKOtEbnJsTyv6LE6m6ZKniqMiFWmm9sRbopbkGs3gMPPfd3Fh8iIA4Ykv5MgaTbqHr4BaoGLJLZNhsrW1Q== @@ -21973,20 +21953,6 @@ uglifyjs-webpack-plugin@^1.2.4: webpack-sources "^1.1.0" worker-farm "^1.5.2" -uglifyjs-webpack-plugin@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/uglifyjs-webpack-plugin/-/uglifyjs-webpack-plugin-2.0.1.tgz#f346af53ed496ce72fef462517d417f62bec3010" - integrity sha512-1HhCHkOB6wRCcv7htcz1QRPVbWPEY074RP9vzt/X0LF4xXm9l4YGd0qja7z88abDixQlnVwBjXsTBs+Xsn/eeQ== - dependencies: - cacache "^11.2.0" - find-cache-dir "^2.0.0" - schema-utils "^1.0.0" - serialize-javascript "^1.4.0" - source-map "^0.6.1" - uglify-js "^3.0.0" - webpack-sources "^1.1.0" - worker-farm "^1.5.2" - uid-number@0.0.6: version "0.0.6" resolved "https://registry.yarnpkg.com/uid-number/-/uid-number-0.0.6.tgz#0ea10e8035e8eb5b8e4449f06da1c730663baa81" From a8381d1602cdecb537f074509107072291fba9f9 Mon Sep 17 00:00:00 2001 From: igor-dv Date: Sat, 24 Nov 2018 01:29:13 +0200 Subject: [PATCH 4/4] Set sourceMap for minimizer. --- lib/core/src/server/preview/iframe-webpack.config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/core/src/server/preview/iframe-webpack.config.js b/lib/core/src/server/preview/iframe-webpack.config.js index c08394ff5fb..56d154b4341 100644 --- a/lib/core/src/server/preview/iframe-webpack.config.js +++ b/lib/core/src/server/preview/iframe-webpack.config.js @@ -100,6 +100,7 @@ export default ({ new TerserWebpackPlugin({ cache: true, parallel: true, + sourceMap: true, terserOptions: { mangle: false, },