Registry / testing / babel-plugin-transform-vite-meta-hot

babel-plugin-transform-vite-meta-hot

JSON →
library1.0.0jsnpmunverified

A Babel plugin that emulates Vite's import.meta.hot API for non-Vite environments, primarily used in test runners like Jest or Mocha. Version 1.0.0 is the initial stable release (January 2023), with no subsequent updates. It transforms import.meta.hot calls into module.hot equivalents, enabling HMR-like code to run in Node.js. Unlike full Vite presets, this is a focused plugin for HMR simulation only. It ships TypeScript type definitions and is part of the babel-vite suite.

npm install babel-plugin-transform-vite-meta-hot
INSTALL
IMPORT
SIG · BABEL-PLUGIN-TRANS
B
babel-plugin-transform-vite-meta-hot
testingjavascriptv1.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default export
import plugin from 'babel-plugin-transform-vite-meta-hot'
const plugin = require('babel-plugin-transform-vite-meta-hot')
ESM works; CJS require is also supported due to dual package support.

Shows setup, input with import.meta.hot, and transformed output using module.hot.

// Install: npm install --save-dev babel-plugin-transform-vite-meta-hot // In .babelrc or babel.config.js: { "plugins": ["babel-plugin-transform-vite-meta-hot"] } // Source code with Vite HMR: if (import.meta.hot) { import.meta.hot.accept((newModule) => { console.log('HMR update'); }); } // After Babel transform: if (module.hot) { module.hot.accept((newModule) => { console.log('HMR update'); }); } // Use with Jest: add to jest.config.js transformIgnorePatterns or babel config.
Debug
Known issues
gotchaOnly transforms import.meta.hot, not other Vite meta properties like import.meta.env or import.meta.glob.
fix
Use babel-plugin-transform-vite-meta-env or babel-plugin-transform-vite-meta-glob for those respectively.
affects: >=1.0.0
gotchaThe transformation is an approximation; module.hot may not be defined in all environments, causing runtime errors.
fix
Add a conditional check like if (typeof module.hot !== 'undefined') before using the transformed code.
affects: >=1.0.0
deprecatedNo active development; last release 1.0.0 over a year ago. Consider using babel-preset-vite for comprehensive Vite compatibility.
fix
Switch to babel-preset-vite which includes this plugin and others.
affects: >=1.0.0
Errors
Common errors & fixes
SyntaxError: /path/to/file.js: Support for the experimental syntax 'importMeta' isn't currently enabled
Babel parser doesn't recognize import.meta syntax; needs appropriate plugin or preset.
fix
Add '@babel/plugin-syntax-import-meta' or use babel-preset-vite which includes it.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
@babel/corerequiredpeer dependency for plugin transformation
Agent activity
15 hits · last 30 days
node
14
OpenAI (training)
1
Resources
babel-plugin-transform-vite-meta-hot — npm install babel-plugin-transform-vite-meta-hot · libregistry