提交学习笔记专用
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.1 KiB

  1. # vite-hot-client
  2. [![NPM version](https://img.shields.io/npm/v/vite-hot-client?color=a1b858&label=)](https://www.npmjs.com/package/vite-hot-client)
  3. Get Vite's `import.meta.hot` at runtime.
  4. **You don't normally need this library directly**. It's designed for embedded UI on top of Vite for client-server communication. For example:
  5. - [`vite-plugin-inspect`](https://github.com/antfu/vite-plugin-inspect)
  6. - [`@unocss/inspector`](https://github.com/unocss/unocss/tree/main/packages/inspector)
  7. - [`@vitest/ui`](https://github.com/vitest-dev/vitest/tree/main/packages/ui)
  8. ## Install
  9. ```bash
  10. npm i vite-hot-client
  11. ```
  12. ## Usage
  13. ```js
  14. import { hot } from 'vite-hot-client'
  15. // import.meta.hot
  16. if (hot) {
  17. hot.on('update', () => {
  18. // ...
  19. })
  20. }
  21. ```
  22. ```js
  23. import { createHotContext } from 'vite-hot-client'
  24. const hot = createHotContext('/path/to/module')
  25. if (hot) {
  26. // ...
  27. }
  28. ```
  29. ## Sponsors
  30. <p align="center">
  31. <a href="https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg">
  32. <img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg'/>
  33. </a>
  34. </p>
  35. ## License
  36. [MIT](./LICENSE) License © 2022 [Anthony Fu](https://github.com/antfu)