kosmos_moduleloader
v0.0.3
Published
``` const packages = require('kosmos_moduleloader')(dirpath,addtionModules); ```
Downloads
10
Readme
usage
const packages = require('kosmos_moduleloader')(dirpath,addtionModules);
dirpath
is a folder that all .js
file will be required as filename.
addtionModules
is an Array
.element of this array can be string
or object
which contains keys name
and packagename
.name
is the name used by required files.And packagename
is required package's name.
example
basic usage
test.js
dir
|-a.js
|-b.js
For above dir structure,in test.js
,we can use const dir = require("kosmos_moduleloader")("./dir");
to load all .js
files under dir
.
We can access them by const a = dir.a;
and etc.
inject package.
If all files under dir
is require a same package(here we name this package testpackage
).you can use const dir = require("kosmos_moduleloader")("./dir",["testpackage"]);
to ensure all .js
files required by this method are able to access testpackage
by direct use name testpackage
.
If you would like to rename testpackage
(here we'd like to rename it as test
),just try const dir = require("kosmos_moduleloader")("./dir",[{name:"test",packagename:"testpackage"]})
.