browser module loader compatible with nodejs
version 0.1.5
!warning:the loaderjs is just used for browser
you can use { require , exports , module.exports } to load modules asynchronously just like the nodejs
run the example
npm install
npm start
you have these modules:
//log.jsrequire('main.js');//test circular referencemodule.exports=function(words){document.body.appendChild(document.createTextNode(words));document.body.appendChild(document.createElement('br'));};//say.jsconstlog=require('log');module.exports=function(){console.log('I am saying');log('I am saying');}//run.jsconstlog=require('log');exports.slow=function(){console.log('slow down');log('slow down');};then,the entry:
//main.jsconstsay=require('say.js');construn=require('run.js');say();run.slow();exports.main='Hello World';the html file:
//test.html
<!DOCTYPE html><htmllang="en"><head><metacharset="UTF-8"><title>Document</title></head><body><scriptsrc="src/loader.js"></script><script>Loader.setEntry('main.js',function(a){console.log(a.main);});</script></body></html>these are in a directory:
/
test.html
say.js
run.js
main.js
these modules will be loaded asynchronously and execute automatically
the outputs:
I am saying
slow down