import-lazy

WebJar for import-lazy

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

import-lazy
Last Version

Last Version

4.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

import-lazy
WebJar for import-lazy
Project URL

Project URL

https://www.webjars.org
Source Code Management

Source Code Management

https://github.com/sindresorhus/import-lazy

Download import-lazy

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/import-lazy/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>import-lazy</artifactId>
    <version>4.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/import-lazy/
implementation 'org.webjars.npm:import-lazy:4.0.0'
// https://jarcasting.com/artifacts/org.webjars.npm/import-lazy/
implementation ("org.webjars.npm:import-lazy:4.0.0")
'org.webjars.npm:import-lazy:jar:4.0.0'
<dependency org="org.webjars.npm" name="import-lazy" rev="4.0.0">
  <artifact name="import-lazy" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='import-lazy', version='4.0.0')
)
libraryDependencies += "org.webjars.npm" % "import-lazy" % "4.0.0"
[org.webjars.npm/import-lazy "4.0.0"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

import-lazy Build Status

Import a module lazily

Install

$ npm install import-lazy

Usage

// Pass in `require` or a custom import function
const 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 properties
const stuff = importLazy('./math-lib');
console.log(stuff.sum(1, 2)); // => 3
console.log(stuff.PHI); // => 1.618033

Note

Destructuring will cause it to fetch eagerly

While you may be tempted to do leverage destructuring, like this:

const {isNumber, isString} = importLazy('lodash');

Note that this will cause immediate property access, negating the lazy loading, and is equivalent to:

import {isNumber, isString} from 'lodash';

Usage with bundlers

If you're using a bundler, like Webpack, you'll have to import your modules like this in order to have them properly bundled:

const importLazy = require('import-lazy');

const _ = importLazy(() => require('lodash'))();

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

Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.

Versions

Version
4.0.0
3.1.0
3.0.0
2.1.0