Require modules lazily
$ npm install --save lazy-req
// pass in `require` or a custom require functionconst lazyReq = require;const _ = ;// Where you would normally do_;// You now instead call it as a function;// It's cached on consecutive calls;// Extract lazy variations of the props you needconst members = 'isNumber' 'isString';// Useful when using destructuring assignment in ES2015const isNumber isString = 'isNumber' 'isString';// Works out of the box for functions and regular propertiesconst stuff = 'sum' 'PHI';console; // => 3console; // => 1.618033
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 = ;const _ = ;// No need to call it as a function but still lazily required_;
MIT © Sindre Sorhus