noader
NodeJS module automatic on-demand lazy loader(NodeJS模块自动按需懒加载器)
Install
npm i noader
Usage
project example
├── test
│ ├── app
│ │ └── module
│ │ └── a.js
│ ├── app2
│ │ └── b.js
│ └── index.js
// a.js
module.exports = {
prop: 'prop a',
fun: function(str){
this.prop = str;
return this.prop;
}
}
// b.js
module.exports = class {
constructor(str) {
this.str = str;
}
fun(str) {
this.str = str;
return this.str;
}
self() {
return this;
}
}
// index.js
const noader = require('noader');
const loader = noader();
console.log(loader.app.module.a);
console.log(loader.app.module.a.prop);
console.log(loader.app.module.a.fun('test1'));
console.log(loader.app2.b);
console.log(loader.app2.b === loader.app2.b);
console.log(loader.app2.b.str);
console.log(loader.app2.b.fun('test2'));
console.log(loader.app2.b.$map.instance);
console.log(loader.app2.b.$map.instance === loader.app2.b.$map.instance);
console.log(loader.app2.b.$map.is_class);
const c = new loader.app2.b('test3');
console.log(c);
console.log(c.str);
console.log('---------------------------------');
const loader2 = noader('../', 'test4');
console.log(loader2.test.app.module.a);
console.log(loader2.test.app2.b);
console.log(loader2.test.app2.b.str);
console.log('---------------------------------');
console.log(loader2.test.app2.b === loader.app2.b);
console.log(loader2.test.app2.b.$map.instance === loader.app2.b.$map.instance);
console.log(loader2.test.app2.b.$map.path);
result
{ prop: 'prop a', fun: [Function: fun] }
prop a
test1
[Function]
true
undefined
test2
{ str: 'test2' }
true
true
{ str: 'test3' }
test3
---------------------------------
{ prop: 'test1', fun: [Function: fun] }
[Function]
test4
---------------------------------
false
false
D:\wwwroot\noader\test/app2/b/
test
npm test
links
License
MIT