Overview of Vite Client HMR API
import.meta.hot object. This API is primarily intended for framework and tooling authors. For handling HMR updates within Vite plugins, use the handleHotUpdate hook instead.website·Indexed 43 days ago
https://vite.dev/guide/A fast build tool for modern web applications. Vite provides a development server with Hot Module Replacement (HMR), dependency pre-bundling, and a production build process. It features a robust Plugin API, support for TypeScript, CSS handling, and Server-Side Rendering (SSR). The documentation covers configuration options for server, build, and preview modes, as well as migration guides from v7 and the Environment API.
import.meta.hot object. This API is primarily intended for framework and tooling authors. For handling HMR updates within Vite plugins, use the handleHotUpdate hook instead.<root>/about.html maps to /about.html). Vite automatically processes assets referenced in HTML elements like <script type="module" src>, <link href>, and <img>. To prevent Vite from processing a specific element, add the vite-ignore attribute.<!doctype html>
<html>
<head>
<link rel="icon" href="/favicon.ico" />
<link rel="stylesheet" href="/src/styles.css" />
</head>
<body>
<img src="/src/images/logo.svg" alt="logo" />
<!-- This script is processed by Vite -->
<script type="module" src="/src/main.js"></script>
<!-- This element is ignored by Vite -->
<img vite-ignore src="https://cdn.example.com/image.png" />
</body>
</html>Vite follows Semantic Versioning (SemVer). The release cadence is as follows:
Native ES imports in the browser do not support bare module imports (e.g., import { someMethod } from 'my-dep'). Vite solves this by detecting bare imports and performing two steps:
/node_modules/.vite/deps/my-dep.js?v=...) so the browser can resolve them.Note: Dependencies are strongly cached via HTTP headers. If you are editing a dependency locally, you may need to clear the browser cache.
Vite automatically dispatches the following HMR events:
vite:beforeUpdate: An update is about to be applied.vite:afterUpdate: An update has just been applied.vite:beforeFullReload: A full page reload is about to occur.vite:beforePrune: Modules no longer needed are about to be pruned.vite:invalidate: A module was invalidated via hot.invalidate().vite:error: An error occurred (e.g., syntax error).vite:ws:disconnect: WebSocket connection lost.vite:ws:connect: WebSocket connection established.@prefresh/vite. These are pre-configured when using templates from create-vite.