Skip to content

Instantly share code, notes, and snippets.

@fjakobs
Created September 29, 2010 18:43
Show Gist options
  • Save fjakobs/603296 to your computer and use it in GitHub Desktop.
Save fjakobs/603296 to your computer and use it in GitHub Desktop.
requireJS loader for node.js
var Script = process.binding('evals').Script;
require.registerExtension(".rjs", function(content) {
require.def = function(name, deps, callback) {
if (!callback) {
callback = deps;
deps = [];
}
var modules = deps.map(function(dep) {
return require(dep);
});
module = callback.apply(this, modules);
}
var sandbox = {};
for (var k in global) {
sandbox[k] = global[k];
}
sandbox.global = sandbox;
sandbox.root = global.root;
sandbox.require = require;
Script.runInNewContext(content, sandbox);
return module;
})
console.log(require("./test2"));
require.def("test2", function() {
var exports = {};
exports.foo = "Juhu";
return exports;
})
@prathe
Copy link

prathe commented Nov 13, 2010

Seems like requireJS now support it:

http://requirejs.org/docs/node.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment