cloader
v0.1.3
Published
Abstraction layer of require().
Downloads
4
Readme
cloader (NodeJS)
Abstraction layer of require().
Install
npm install cloader
Quick Start
loader.js
Create a loader.js in your project root and instantiate a ComponentLoader:
// Creates a ComponentLoader instance
// Attaches it to GLOBAL.load
require('cloader')('load');
The next step is to add your libraries and virtual packages. They're relative to your project root.
// Libraries
load.addLibrary('lib/');
load.addLibrary('node_modules/mySharedPackage/lib/');
// Virtual Packages
load.addPackage('auth-api', 'packages/auth_api/index.js');
app.js
The loader is defined inside a global variable, this means that you only have to require it inside your entry script.
// app.js
require('loader.js');
Because it's in a separate loader.js file, this is also possible:
// mocha
--require=loader.js
random-module.js
Pretty random example but this is merely an illustration.
// Packages, both virtual and real
var AuthApi = load.p( 'auth-api' ),
mongoose = load.p( 'mongoose' ),
crypto = load.p( 'crypto' );
// Modules
var UserModel = load.m( 'Models/UserSystem/User' ),
Cookie = load.m( 'Models/UserSystem/Cookie' ),
formSanitizer = load.m( 'Tools/FormSanitizer' );
// Your specific module code (or unit-test)
...
You still load modules using their directory path, but those paths now behave like absolute paths and they are more easily readable and comprehensible.
You can also merge or separate your libraries and turn your virtual packages into real packages without having to change individual modules.
Documentation
Go to the wiki for more in-depth documentation and configuration options.
License
GPLv3