import-lazy
Import a module lazily
Install
$ npm install import-lazy
Usage
// Pass in `require` or a custom import functionconst importLazy = require;const _ = ; // Instead of referring to its exported properties directly…_; // …it's cached on consecutive calls_; // Works out of the box for functions and regular propertiesconst stuff = ;console; // => 3console; // => 1.618033
Warning: Destructuring will cause it to fetch eagerly
While you may be tempted to do leverage destructuring, like this:
const isNumber isString = ;
Note that this will cause immediate property access, negating the lazy loading, and is equivalent to:
;
Related
- resolve-from - Resolve the path of a module from a given path
- import-from - Import 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