enhanced-require
More features for node.js require.
- loader support
require.ensure
- AMD
require
, define
(from require.js) require.context
Asynchron require functions are really async. They do not use the sync node.js require, but use a async resolving and async readFile.
Add this line to a node.js module to activate the enhanced features in that module:
require = require("enhanced-require")(module);
if(typeof define != "function") var define = require.define;
Than you can use them:
var fileContent = require("raw!"+__filename);
var template = require("./my-template.jade");
var html = template({content: fileContent});
var directoryRequire = require.context("raw!./subdir");
var txtFile = directoryRequire("./aFile.txt");
require.ensure(["./someFile.js"], function(require) {
var someFile = require("./someFile.js");
});
require.define(["./aDep"], function(aDep) {
aDep.run();
});
require(["./bDep"], function(bDep) {
bDep.run();
});
Future Plans
require("enhanced-require/install")
enables support for all modules.
License
Copyright (c) 2012 Tobias Koppers
MIT (http://www.opensource.org/licenses/mit-license.php)