export-lazy-prop

1.0.0 • Public • Published

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.

Package Sidebar

Install

npm i export-lazy-prop

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

6.51 kB

Total Files

4

Last publish

Collaborators

  • dailyrandomphoto