A lightweight utility (v2.1.0, actively maintained) that allows you to access Vite's HMR API (`import.meta.hot`) at runtime, even in contexts where `import.meta.hot` is not directly available (e.g., inside iframes, worker threads, or dynamically evaluated code). It provides `hot`, `createHotContext`, and `tryCreateHotContext` functions. Key differentiator: solves the problem of accessing Vite's HMR client from outside standard Vite-managed modules, enabling dev tools like `vite-plugin-inspect` to communicate with the dev server over HMR. Requires `vite` ^2.6.0 || ^3.0.0 || ^4.0.0 || ^5.0.0-0 || ^6.0.0-0 || ^7.0.0-0. Ships TypeScript definitions and is ESM-only since v2.
npm install vite-hot-clientVerified import paths — ran on the pinned version, not inferred.
Shows using the 'hot' export and createHotContext() for custom HMR communication.
Use ES module imports (import { hot } from 'vite-hot-client'); remove any require() calls.Replace hot.on(...) with createHotContext('/path/to/module').on(...) or use the exported 'hot' (which is pre-bound to the current module).Use tryCreateHotContext to safely create a context, which returns null instead of throwing.
Guard usage with process.env.NODE_ENV !== 'production' or similar.
Check if hot is truthy before using: if (hot) { ... }Set 'type': 'module' in package.json or use .mjs extension.
Ensure vite-hot-client is symlinked or installed correctly; it is ESM-only since v2. Use dynamic import() if necessary.
Access 'hot' inside a function or after the module is loaded; it's set synchronously when import.meta.hot is available.
Check for null: const ctx = createHotContext(...); if (ctx) { ctx.on(...) }