1.0.0 • Published 4 years ago

export-lazy-prop v1.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

export-lazy-prop

NPM Version LICENSE Build Status code style: prettier

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

License

Copyright (c) 2019 dailyrandomphoto. Licensed under the MIT license.