From 5d20599da75837c6904e146de1820911eca34dd7 Mon Sep 17 00:00:00 2001 From: "Valentin D. Pinkman" Date: Mon, 25 Jun 2018 15:35:26 +0200 Subject: [PATCH 1/2] remove mangling when building rendered in production --- package.json | 1 + scripts/compile.sh | 2 +- webpack/main.config.js | 2 +- webpack/renderer.config.js | 23 +++++++++++++++++++++++ yarn.lock | 13 +++++++++++++ 5 files changed, 39 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 82f4e681..8c01668e 100644 --- a/package.json +++ b/package.json @@ -156,6 +156,7 @@ "prettier": "^1.13.5", "react-hot-loader": "^4.3.2", "react-test-renderer": "^16.4.1", + "uglifyjs-webpack-plugin": "^1.2.6", "webpack": "^4.6.0", "webpack-bundle-analyzer": "^2.11.1", "webpack-cli": "^2.0.14", diff --git a/scripts/compile.sh b/scripts/compile.sh index 78c063ea..d5c892d3 100644 --- a/scripts/compile.sh +++ b/scripts/compile.sh @@ -7,6 +7,6 @@ SENTRY_URL=https://db8f5b9b021048d4a401f045371701cb@sentry.io/274561 NODE_ENV=production rm -rf ./node_modules/.cache dist -yarn +JOBS=max yarn yarn run webpack-cli --mode production --config webpack/internals.config.js yarn run electron-webpack diff --git a/webpack/main.config.js b/webpack/main.config.js index 95764b38..ace38ff1 100644 --- a/webpack/main.config.js +++ b/webpack/main.config.js @@ -4,7 +4,7 @@ const rules = require('./rules') const config = { mode: __ENV__, - plugins: plugins('main'), + plugins: [...plugins('main')], resolve, module: { rules, diff --git a/webpack/renderer.config.js b/webpack/renderer.config.js index 4a8a6a1d..901bedcd 100644 --- a/webpack/renderer.config.js +++ b/webpack/renderer.config.js @@ -1,9 +1,29 @@ const HardSourceWebpackPlugin = require('hard-source-webpack-plugin') +const UglifyJsPlugin = require('uglifyjs-webpack-plugin') const plugins = require('./plugins') const resolve = require('./resolve') const rules = require('./rules') +const getOptimization = env => { + const optimization = { + minimizer: [ + // Default Config without mangling + new UglifyJsPlugin({ + parallel: true, + sourceMap: true, + uglifyOptions: { + mangle: false, + compress: { + ecma: 7, + }, + }, + }), + ], + } + return env === 'production' ? optimization : undefined +} + const config = { mode: __ENV__, plugins: [...plugins('renderer'), new HardSourceWebpackPlugin()], @@ -14,6 +34,9 @@ const config = { devServer: { historyApiFallback: true, }, + optimization: { + ...getOptimization(__ENV__), + }, } if (__DEV__) { diff --git a/yarn.lock b/yarn.lock index fe2073e1..bbfee6d8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13797,6 +13797,19 @@ uglifyjs-webpack-plugin@^1.2.4, uglifyjs-webpack-plugin@^1.2.5: webpack-sources "^1.1.0" worker-farm "^1.5.2" +uglifyjs-webpack-plugin@^1.2.6: + version "1.2.6" + resolved "https://registry.yarnpkg.com/uglifyjs-webpack-plugin/-/uglifyjs-webpack-plugin-1.2.6.tgz#f4bb44f02431e82b301d8d4624330a6a35729381" + dependencies: + cacache "^10.0.4" + find-cache-dir "^1.0.0" + schema-utils "^0.4.5" + serialize-javascript "^1.4.0" + source-map "^0.6.1" + uglify-es "^3.3.4" + 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 cea276818c5f7d98fa4983afee9ba70125b4c519 Mon Sep 17 00:00:00 2001 From: "Valentin D. Pinkman" Date: Mon, 25 Jun 2018 18:30:02 +0200 Subject: [PATCH 2/2] cleanup webpack main.config --- webpack/main.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webpack/main.config.js b/webpack/main.config.js index ace38ff1..95764b38 100644 --- a/webpack/main.config.js +++ b/webpack/main.config.js @@ -4,7 +4,7 @@ const rules = require('./rules') const config = { mode: __ENV__, - plugins: [...plugins('main')], + plugins: plugins('main'), resolve, module: { rules,