export-lazy-prop
v1.0.0
Published
Export a lazily evaluated property.
Downloads
3
Maintainers
Readme
export-lazy-prop
Export a lazily evaluated property.
Installation
npm install export-lazy-prop
Usages
// util/index.js
exports.foo = require("./foo");
exports.bar = require("./bar");
// some.js
const util = require("./util");
// foo.js and bar.js are loaded
util.foo();
In this case, even if bar.js
is not used, it will still be loaded from the file system.
With export-lazy-prop
, modules will be loaded on demand.
// util/index.js
const exportLazyProp = require("export-lazy-prop");
exportLazyProp(exports, "foo", () => require("./foo"));
exportLazyProp(exports, "bar", () => require("./bar"));
// some.js
const util = require("./util");
// will not load foo.js and bar.js
util.foo();
// foo.js is loaded
Or
// util/index.js
const exportLazyProp = require("export-lazy-prop");
exportLazyProp(exports, {
foo: () => require("./foo"),
bar: () => require("./bar"),
});
Related
- define-lazy-prop - Define a lazily evaluated property on an object
- import-lazy - Import a module lazily
License
Copyright (c) 2019 dailyrandomphoto. Licensed under the MIT license.