Skip to content
This repository has been archived by the owner on Oct 9, 2020. It is now read-only.

Commit

Permalink
rollup sfx optimization update
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Jul 23, 2015
1 parent 30528a3 commit a64acb5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
10 changes: 8 additions & 2 deletions lib/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ function processOpts(opts_, outFile) {

sourceMaps: false,
sourceMapContents: opts_ && opts_.sourceMaps == 'inline',
lowResSourceMaps: false
lowResSourceMaps: false,

// for all es6 sfx bundles, use rollup
esOptimize: true,

// sfx bundles have module names compressed
sfxEncodings: true
};
for (var key in opts_)
opts[key] = opts_[key];
Expand Down Expand Up @@ -208,7 +214,7 @@ Builder.prototype.buildSFX = function(expression, outFile, opts) {
entryPoints = trace.entryPoints;

// attempt optimization for all ES6
return require('./sfx-optimize').optimizeSFXTree(tree, entryPoints, opts);
return opts.esOptimize !== false && require('./sfx-optimize').optimizeSFXTree(tree, entryPoints, opts);
})
.then(function(optimizedOutputs) {
// was all ES6, has already been compiled separately
Expand Down
21 changes: 12 additions & 9 deletions lib/sfx-optimize.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function getLoad(tree, path) {
var address = toFileURL(path);
var load;
Object.keys(tree).some(function(name) {
if (tree[name].address == address || tree[name].name == path) {
if (tree[name].normalized == address) {
load = tree[name];
return true;
}
Expand All @@ -22,19 +22,22 @@ exports.optimizeSFXTree = function(tree, entryPoints, opts) {
if (!allES || entryPoints.length > 1)
return;

var entryName = entryPoints[0]
var entryName = entryPoints[0];

// whole tree is ES, we can use rollup to optimize for SFX!
return rollup.rollup({
entry: fromFileURL(tree[entryPoints[0]].address),
resolvePath: function(id, importer, options) {
return getLoad(tree, importer).depMap[id];
},
resolveExternal: function(id, importer, options) {
return getLoad(tree, importer).depMap[id];
resolveId: function(id, importer, options) {
if (importer) {
var parentLoad = getLoad(tree, importer);

if (parentLoad)
return parentLoad.depMap[id] && fromFileURL(tree[parentLoad.depMap[id]].normalized);
}
return id;
},
load: function(path, options) {
return getLoad(tree, path).metadata.originalSource;
return getLoad(tree, path).originalSource;
}
})
.then(function(bundle) {
Expand All @@ -44,7 +47,7 @@ exports.optimizeSFXTree = function(tree, entryPoints, opts) {

// we dont have this option in builder, as its assumed the user assigns to the global from within the ES6 module
// its probably worth introducing this option
moduleName: 'test'
moduleName: '__sfx'
});

return [{
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dependencies": {
"glob": "^5.0.10",
"mkdirp": "^0.5.1",
"rollup": "^0.8.1",
"rollup": "^0.11.4",
"rsvp": "^3.0.18",
"source-map": "^0.4.2",
"systemjs": "git://github.com/systemjs/systemjs#master",
Expand Down
3 changes: 1 addition & 2 deletions test/test-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,7 @@ suite('Bundle Format', function() {
})
.then(function() {
return testPhantom('test/test-sfx-amd.html');
})
.catch(done);
});
});
});

Expand Down

0 comments on commit a64acb5

Please sign in to comment.