Skip to content

Instantly share code, notes, and snippets.

@frostney
Created February 23, 2015 21:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frostney/9cdc735cc1e26487328e to your computer and use it in GitHub Desktop.
Save frostney/9cdc735cc1e26487328e to your computer and use it in GitHub Desktop.
Minimal CommonJS loader
(function(root) {
var modules = {};
var cache = {};
root.require = function(name) {
if (!Object.hasOwnProperty.call(cache, name)) {
var module = {
id: name,
};
var exports = {};
var require = root.require;
modules[name].call(module, require, module, exports);
cache[name] = (Object.hasOwnProperty.call(module, 'exports')) ? module.exports : exports;
}
return cache[name];
};
// factory (require, module, exports)
root.require.register = function(name, factory) {
modules[name] = factory;
};
})(window);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment