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

Commit

Permalink
remove global require setting for AMD sfx
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Oct 1, 2015
1 parent 357f069 commit a8f9891
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions templates/amd-helpers.js
Expand Up @@ -136,14 +136,8 @@
return require.call(loader, names, callback, errback, module.id);
});

// set global require to AMD require
var curRequire = __global.require;
__global.require = require;

var output = factory.apply(exportsIndex == -1 ? __global : exports, depValues);

__global.require = curRequire;

if (typeof output == 'undefined' && module)
output = module.exports;

Expand Down Expand Up @@ -224,4 +218,4 @@
}));
loader.amdDefine = define;
loader.amdRequire = require;
})(typeof self != 'undefined' ? self : global);
})(typeof self != 'undefined' ? self : global);

3 comments on commit a8f9891

@OliverJAsh
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to think of a use case where you would need this.

Say you have a SFX bundle with foo and bar. foo wants to async require bar:

// foo.js
define([], function () {
    require(['bar'], function (module) {
        console.log(module);
    });

    return 'foo module';
});

The SystemJS micro loader has registered foo and bar. In this case, you would want the micro loader to provide window.require?

@guybedford
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The micro-loader doesn't support dynamic requires at all anymore so I think the only valid use case is a sync AMD require of the form require('x') where the require was not taken from the callback, but that's not something that is expected as standard.

@OliverJAsh
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. In that case, big 👍 😄

Please sign in to comment.