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);