Created
September 29, 2010 18:43
-
-
Save fjakobs/603296 to your computer and use it in GitHub Desktop.
requireJS loader for node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require.def("test2", function() { | |
var exports = {}; | |
exports.foo = "Juhu"; | |
return exports; | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Seems like requireJS now support it:
http://requirejs.org/docs/node.html