simpler-browser-require
simpler-browser-require is an even simpler, node.js-like require()
for the browser. It is not an asynchronous script loader, and it only works with absolute paths (hence simpler).
Usage
Wrapping each module in a require.register
call:
require;
...allows the require
function to return the module's public contents:
var lib = ;
...exposed by decorating the exports
object:
var myModuleVar = 'my module'; exports { return myModuleVar;};
...or overwritting the exports
object completely:
{ thismyVar = 'my instance var';}; MyModuleprototype { return thismyVar;}; moduleexports = MyModule;
Lazy modules
Passing a string (instead of a function) to require.register
enables lazy evaluation of module contents. The module will be parsed and evaluated only when require
'd:
require;
The raw source is retrievable via require.raw(path)
:
localStorage;windowrequire;// ...var myModule = ;console; //=> 'foo'