Skip to content

Instantly share code, notes, and snippets.

@isaacs
Forked from tim-smart/@example_register.js
Created March 11, 2010 06:16
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 isaacs/328895 to your computer and use it in GitHub Desktop.
Save isaacs/328895 to your computer and use it in GitHub Desktop.
// This returns a Javascript string
require.registerExtension('.coffee', function(async, source, callback) {
return compileCoffee(source);
});
// True
require('coffee').test === 123;
// This returns a object
require.registerExtension('.mu', function(async, source, callback) {
return {
html: compileTemplate(source),
test: 321
};
});
// True
require('template').test === 321;
// this one returns the module function
require.registerExtension(".foo", function (async, source, callback) {
return function (exports, require, module, __filename, __dirname) {
exports.hello = "world"
}
});
require("foofile").hello === "world"
exports.test: 123
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment