From f546dc3790edd4e0b310caccdc273f31a717258c Mon Sep 17 00:00:00 2001 From: Tadeu Zagallo Date: Sun, 27 Dec 2015 06:00:39 -0800 Subject: [PATCH] Move WPO to the minify step Summary: public The Whole Program Optimisation (WPO) pass is quite slow, and can make it painful to iterate when having `dev=false`. Move it to happen only when both `dev=false` and `minify=true`. Reviewed By: davidaurelio Differential Revision: D2773941 fb-gh-sync-id: ac5ca4e1286e233c2d175eecdbf7494d5d3497b2 --- packager/react-packager/src/Bundler/Bundle.js | 38 +++++++++---------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/packager/react-packager/src/Bundler/Bundle.js b/packager/react-packager/src/Bundler/Bundle.js index 11a892f79..b5e591c8f 100644 --- a/packager/react-packager/src/Bundler/Bundle.js +++ b/packager/react-packager/src/Bundler/Bundle.js @@ -109,24 +109,6 @@ class Bundle { } this._source = _.pluck(this._modules, 'code').join('\n'); - - if (dev) { - return this._source; - } - - const wpoActivity = Activity.startEvent('Whole Program Optimisations'); - const result = require('babel-core').transform(this._source, { - retainLines: true, - compact: true, - plugins: require('../transforms/whole-program-optimisations'), - inputSourceMap: this.getSourceMap(), - }); - - this._source = result.code; - this._sourceMap = result.map; - - Activity.endEvent(wpoActivity); - return this._source; } @@ -187,13 +169,29 @@ class Bundle { return this._minifiedSourceAndMap; } - const source = this._getSource(dev); + let source = this._getSource(dev); + let map = this.getSourceMap(); + + if (!dev) { + const wpoActivity = Activity.startEvent('Whole Program Optimisations'); + const wpoResult = require('babel-core').transform(source, { + retainLines: true, + compact: true, + plugins: require('../transforms/whole-program-optimisations'), + inputSourceMap: map, + }); + Activity.endEvent(wpoActivity); + + source = wpoResult.code; + map = wpoResult.map; + } + try { const minifyActivity = Activity.startEvent('minify'); this._minifiedSourceAndMap = UglifyJS.minify(source, { fromString: true, outSourceMap: this._sourceMapUrl, - inSourceMap: this.getSourceMap(), + inSourceMap: map, output: {ascii_only: true}, }); Activity.endEvent(minifyActivity);