lazy-req 
Require modules lazily
Install
$ npm install --save lazy-req
Usage
const lazyReq = require('lazy-req')(require);
const _ = lazyReq('lodash');
_.isNumber(2);
_().isNumber(2);
_().isString('unicorn');
const members = lazyReq('lodash')('isNumber', 'isString');
const {isNumber, isString} = lazyReq('lodash')('isNumber', 'isString');
const stuff = lazyReq('./math-lib')('sum', 'PHI');
console.log(stuff.sum(1, 2));
console.log(stuff.PHI);
Proxy support in Node.js 6 or later
If you use Node.js 6 or later, you can take advantage of ES2015 proxies and don't need to call it as a function.
const lazyReq = require('lazy-req').proxy(require);
const _ = lazyReq('lodash');
_.isNumber(2);
Related
- resolve-from - Resolve the path of a module from a given path
- req-from - Require a module from a given path
- resolve-pkg - Resolve the path of a package regardless of it having an entry point
- lazy-value - Create a lazily evaluated value
- define-lazy-prop - Define a lazily evaluated property on an object
License
MIT © Sindre Sorhus