Skip to content

Instantly share code, notes, and snippets.

@roberttod
Last active December 16, 2015 19:09
Show Gist options
  • Save roberttod/5482633 to your computer and use it in GitHub Desktop.
Save roberttod/5482633 to your computer and use it in GitHub Desktop.
Change the context of require and then change back again
// Change require to new context
var newRequire = require.config({
context: "new"
});
// Define and then require module under context "new"
define("someModule", [], function () {return "newContext"; });
newRequire(["someModule"], function (something) {console.log(something); });
// Revert back to global context
require.config({
context: "_"
});
// Define and then require module under global context
define("someModule", [], function () {return "globalContext"; });
require(["someModule"], function (something) {console.log(something); });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment