Cache requires to be lazy-loaded when needed.
Install with npm:
$ npm install lazy-cache --save
var utils = require;
Use as a property on
The module is also added as a property to the
so it can be called without having to call a function first.
var utils = require;// `npm install glob`;// glob syncconsole;// glob asyncutils;
Use as a function
var utils = require;var glob = ;// `glob` is a now a function that may be called when needed;
An alias may be passed as the second argument if you don't want to use the automatically camel-cased variable name.
var utils = require;// alias `ansi-yellow` as `yellow`;console;
var utils = require;// temporarily re-assign `require` to trick browserifyvar fn = require;require = utils;// list module dependencies (here, `require` is actually `lazy-cache`);require = fn; // restore the native `require` function/*** Now you can use glob with the `utils.glob` variable*/// syncconsole;// asyncutils;
In certain rare edge cases it may be necessary to unlazy all lazy-cached dependencies (5 reported cases after ~30 million downloads).
To force lazy-cache to immediately invoke all dependencies, do:
processenvUNLAZY = true;
You might also be interested in these projects:
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Generate readme and API documentation with verb:
$ npm install verb && npm run docs
Or, if verb is installed globally:
Install dev dependencies:
$ npm install -d && npm test
This file was generated by verb, v0.9.0, on April 22, 2016.