jsloader
v1.0.1
Published
## Features:
Downloads
6
Readme
JsLoader
Features:
- Loading synchronously AMD modules inside Node.js
- Common API for loading AMD and CommonJs modules
- Namespacing JavaScript code
Examples
Loading modules
var auto = require("jsloader"),
SomeAMDModule = auto.load("modules/amd/Some"), // loads Some.js files
OtherCommonJSModule = auto.load("modules/commonjs/Other"); // loads Other.js file
Loading namespaced code
Autoloader scans for package.json files in every node module so namespaces are loaded automatically.
/node_modules/foo/package.json
{
"name": "foo",
"autoload": {
"amd": {
"SomeNamespace/Foo": "folder/with/Foo",
},
"commonjs": {
"SomeNamespace/Foo/Bar": "folder/with/commonjs/Foo"
}
}
}
/node_modules/bar/package.json
{
"name": "bar",
"autoload": {
"amd": {
"SomeNamespace/Bar": "folder/with/Bar"
}
}
}
/yourscript.js
var auto = require("jsloader"),
Foor = auto.load("SomeNamespace/Foo/Foor"), // loads "/node_modules/foo/folder/with/Foo/Foor.js" using AMD
Boor = auto.load("SomeNamespace/Bar/Boor"), // loads "/node_modules/bar/folder/with/Bar/Boor.js" using AMD
Booz = auto.load("SomeNamespace/Foo/Bar/Booz"); // loads "/node_modules/foo/folder/with/commonjs/Foo/Booz.js" using CommonJS