Skip to content

Commit

Permalink
Move WPO to the minify step
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tadeuzagallo authored and facebook-github-bot-4 committed Dec 27, 2015
1 parent 739a6d6 commit f546dc3
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions packager/react-packager/src/Bundler/Bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f546dc3

Please sign in to comment.