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

Commit

Permalink
AMD in bundles to use "bundle" meta over "register" format meta
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Aug 4, 2015
1 parent efaaeed commit 037ceb6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 1 addition & 2 deletions compilers/amd.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,8 @@ exports.compile = function(load, opts, loader) {

// because we've blindly replaced the define statement from AMD with a System.registerDynamic call
// we have to ensure we still trigger any AMD guard statements in the code by creating a dummy define which isn't called
// "register" added to ensure AMD at the top of a bundle allows the bundle to be detected properly
return Promise.resolve({
source: '"format register";(function() {\nvar _removeDefine = System.get("@@amd-helpers").createDefine();\n' + output + '\n_removeDefine();\n})();',
source: '(function() {\nvar _removeDefine = System.get("@@amd-helpers").createDefine();\n' + output + '\n_removeDefine();\n})();',
sourceMap: compiler.getSourceMap(),
sourceMapOffset: 2
});
Expand Down
11 changes: 11 additions & 0 deletions lib/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,17 @@ function compileOutputs(loader, tree, opts, sfxEntryPoints, cache) {
}));
})

// if any module in the bundle is AMD, add a "bundle" meta to the bundle
// this can be deprecated if https://github.com/systemjs/builder/issues/264 lands
.then(function() {
var hasAMD = modules.some(function(name) {
return tree[name].format == 'amd';
});

if (hasAMD)
outputs.unshift('"bundle"');
})

.then(function() {
if (sfxEntryPoints)
return wrapSFXOutputs(loader, tree, outputs, sfxEntryPoints, opts);
Expand Down

0 comments on commit 037ceb6

Please sign in to comment.