Skip to content

Instantly share code, notes, and snippets.

@tim-smart
Created February 2, 2010 22:53
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 tim-smart/293140 to your computer and use it in GitHub Desktop.
Save tim-smart/293140 to your computer and use it in GitHub Desktop.
exports.hotRequire = function(variable, path, prop = null) {
if ("string" === typeof prop)
module.parent.exports.scope[variable] = require(path)[prop];
else
module.parent.exports.scope[variable] = require(path);
(function(variable, path, prop) {
process.watchFile(path, function() {
if ("string" === typeof prop)
module.parent.exports.scope[variable] = require(path)[prop];
else
module.parent.exports.scope[variable] = require(path);
});
})(variable, path, prop);
}
var hotRequire = require("./hot_require").hotRequire;
hotRequire("someVariable", "module");
someVariable.Export();
// OR
//
hotRequire("someVariable", "module", "Export");
someVariable()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment