Vite Plugin Node is a crucial Vite plugin specifically crafted to elevate the development experience for Node.js server applications by seamlessly integrating Hot Module Replacement (HMR). This integration allows developers to harness Vite's renowned speed for compilation and its powerful HMR features directly within their backend services, drastically accelerating iteration cycles during development. The current stable version, 8.0.0, is explicitly designed to be compatible with Vite 8.x.x, reflecting a release cadence that closely mirrors Vite's major version updates. A primary differentiator of this plugin is its extensive, out-of-the-box support for a wide array of popular Node.js frameworks, including Express, Fastify, Koa, and Nest. Beyond these, it also provides the flexibility to define custom request adapters, accommodating virtually any other Node.js framework or server setup. Furthermore, it offers developers a choice in TypeScript compilation, allowing them to utilize either Vite's default Oxc-based transformer or opt for SWC. The SWC option is particularly beneficial for projects that require specific TypeScript features such as decorator metadata. This comprehensive functionality streamlines Node.js backend development, embedding it deeply and efficiently within the modern Vite ecosystem, reducing overhead and maximizing developer productivity.
npm install vite-plugin-nodeVerified import paths — ran on the pinned version, not inferred.
Sets up a basic Express.js server with Vite-powered Hot Module Replacement (HMR) using `vite-plugin-node`, demonstrating `vite.config.ts` and the server entry point.
Always consult the version compatibility table in the documentation and upgrade vite-plugin-node to the version matching your Vite major version (e.g., Vite 8.x.x needs vite-plugin-node 8.x.x).
If configuring 'tsCompiler' to 'swc', ensure you run 'npm install -D @swc/core' in your project.
Ensure 'exportName' in your vite.config.ts (default 'viteNodeApp') matches the exact named export (e.g., 'export const viteNodeApp = app;') in your server entry file.
Install the required SWC compiler: `npm install -D @swc/core`.
Verify that the 'exportName' (default 'viteNodeApp') in your plugin configuration precisely matches the named export in your server entry file, e.g., `export const viteNodeApp = app;`.
Ensure your project is configured for ESM (e.g., add `"type": "module"` to your `package.json`) and use the `import { VitePluginNode } from 'vite-plugin-node';` syntax in your `vite.config.ts`.