{"id":13447358,"url":"https://github.com/sindresorhus/import-lazy","last_synced_at":"2025-05-15T12:00:19.353Z","repository":{"id":19763703,"uuid":"23021454","full_name":"sindresorhus/import-lazy","owner":"sindresorhus","description":"Import a module lazily","archived":false,"fork":false,"pushed_at":"2022-07-11T08:45:05.000Z","size":29,"stargazers_count":248,"open_issues_count":1,"forks_count":17,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-05-15T01:35:12.775Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sindresorhus.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/security.md","support":null},"funding":{"github":"sindresorhus","open_collective":"sindresorhus","custom":"https://sindresorhus.com/donate"}},"created_at":"2014-08-16T15:56:46.000Z","updated_at":"2025-05-13T13:08:38.000Z","dependencies_parsed_at":"2022-09-05T16:51:45.236Z","dependency_job_id":null,"html_url":"https://github.com/sindresorhus/import-lazy","commit_stats":null,"previous_names":["sindresorhus/lazy-req"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fimport-lazy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fimport-lazy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fimport-lazy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fimport-lazy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/import-lazy/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254337612,"owners_count":22054253,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T05:01:15.337Z","updated_at":"2025-05-15T12:00:19.159Z","avatar_url":"https://github.com/sindresorhus.png","language":"JavaScript","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://sindresorhus.com/donate","https://tidelift.com/subscription/pkg/npm-import-lazy?utm_source=npm-import-lazy\u0026utm_medium=referral\u0026utm_campaign=readme"],"categories":["JavaScript","包","Packages","Miscellaneous"],"sub_categories":["其他","Miscellaneous"],"readme":"# import-lazy\n\n\u003e Import a module lazily\n\n\n## Install\n\n```\n$ npm install import-lazy\n```\n\n\n## Usage\n\n```js\n// Pass in `require` or a custom import function\nconst importLazy = require('import-lazy')(require);\nconst _ = importLazy('lodash');\n\n// Instead of referring to its exported properties directly…\n_.isNumber(2);\n\n// …it's cached on consecutive calls\n_.isNumber('unicorn');\n\n// Works out of the box for functions and regular properties\nconst stuff = importLazy('./math-lib');\nconsole.log(stuff.sum(1, 2)); // =\u003e 3\nconsole.log(stuff.PHI); // =\u003e 1.618033\n```\n\n\n## Note\n\n### Destructuring will cause it to fetch eagerly\n\nWhile you may be tempted to do leverage destructuring, like this:\n\n```js\nconst {isNumber, isString} = importLazy('lodash');\n```\n\nNote that this will cause immediate property access, negating the lazy loading, and is equivalent to:\n\n```js\nimport {isNumber, isString} from 'lodash';\n```\n\n### Usage with bundlers\n\nIf you're using a bundler, like Webpack, you'll have to [import your modules like this](https://github.com/webpack/webpack/issues/9155) in order to have them properly bundled:\n\n```js\nconst importLazy = require('import-lazy');\n\nconst _ = importLazy(() =\u003e require('lodash'))();\n```\n\n\n## Related\n\n- [resolve-from](https://github.com/sindresorhus/resolve-from) - Resolve the path of a module from a given path\n- [import-from](https://github.com/sindresorhus/import-from) - Import a module from a given path\n- [resolve-pkg](https://github.com/sindresorhus/resolve-pkg) - Resolve the path of a package regardless of it having an entry point\n- [lazy-value](https://github.com/sindresorhus/lazy-value) - Create a lazily evaluated value\n- [define-lazy-prop](https://github.com/sindresorhus/define-lazy-prop) - Define a lazily evaluated property on an object\n\n\n---\n\n\u003cdiv align=\"center\"\u003e\n\t\u003cb\u003e\n\t\t\u003ca href=\"https://tidelift.com/subscription/pkg/npm-import-lazy?utm_source=npm-import-lazy\u0026utm_medium=referral\u0026utm_campaign=readme\"\u003eGet professional support for this package with a Tidelift subscription\u003c/a\u003e\n\t\u003c/b\u003e\n\t\u003cbr\u003e\n\t\u003csub\u003e\n\t\tTidelift helps make open source sustainable for maintainers while giving companies\u003cbr\u003eassurances about security, maintenance, and licensing for their dependencies.\n\t\u003c/sub\u003e\n\u003c/div\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fimport-lazy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Fimport-lazy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fimport-lazy/lists"}