// Pass in `require` or a custom import functionconst importLazy = require('import-lazy')(require);const _ = importLazy('lodash');// Instead of referring to its exported properties directly…_.isNumber(2);// …it's cached on consecutive calls_.isNumber('unicorn');// Works out of the box for functions and regular propertiesconst stuff = importLazy('./math-lib');console.log(stuff.sum(1, 2)); // => 3console.log(stuff.PHI); // => 1.618033
Warning: Destructuring will cause it to fetch eagerly
While you may be tempted to do leverage destructuring, like this: