Skip to content

Latest commit

 

History

History
54 lines (35 loc) · 1.3 KB

README.md

File metadata and controls

54 lines (35 loc) · 1.3 KB

rwin

Actual version published on NPM Downloads

Like to keep your requires in the script header?

Tired to load modules that will possibly not been used and overloading your RAM?

Require When It Needeed is a lightweight tool that loads (synchronously) the required module only when and if you really need it!

This Node.js module is under MIT License.

Install :

$ npm install rwin

Usage :

lib = rwin(imports, [dirname]);

Where :

lib : is an object that contains an accessor for each required modules

imports : is an object that contains the accessor name paired with the module path

dirname : is the source path, generally __dirname (useless if You only require installed modules)

Example:

var rwin,
    imports,
    lib;

rwin = require('rwin');

imports = {
    installedModule: 'installed-module',
    uninstalledModule: '/uninstalled-module/path'
};

lib = rwin(imports, __dirname);

// At this point, rwin is the only one loaded module (and its own dependencies)

console.log(lib.installedModule); // loads the module & returns it to the console