You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.5 KiB

пре 4 година
  1. # import-fresh [![Build Status](https://travis-ci.org/sindresorhus/import-fresh.svg?branch=master)](https://travis-ci.org/sindresorhus/import-fresh)
  2. > Import a module while bypassing the [cache](https://nodejs.org/api/modules.html#modules_caching)
  3. Useful for testing purposes when you need to freshly import a module.
  4. ## Install
  5. ```
  6. $ npm install import-fresh
  7. ```
  8. ## Usage
  9. ```js
  10. // foo.js
  11. let i = 0;
  12. module.exports = () => ++i;
  13. ```
  14. ```js
  15. const importFresh = require('import-fresh');
  16. require('./foo')();
  17. //=> 1
  18. require('./foo')();
  19. //=> 2
  20. importFresh('./foo')();
  21. //=> 1
  22. importFresh('./foo')();
  23. //=> 1
  24. ```
  25. ## import-fresh for enterprise
  26. Available as part of the Tidelift Subscription.
  27. The maintainers of import-fresh and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-import-fresh?utm_source=npm-import-fresh&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
  28. ## Related
  29. - [clear-module](https://github.com/sindresorhus/clear-module) - Clear a module from the import cache
  30. - [import-from](https://github.com/sindresorhus/import-from) - Import a module from a given path
  31. - [import-cwd](https://github.com/sindresorhus/import-cwd) - Import a module from the current working directory
  32. - [import-lazy](https://github.com/sindresorhus/import-lazy) - Import modules lazily