Skip to content

@dudousxd/nestjs-inertia-vite

Terminal window
pnpm add @dudousxd/nestjs-inertia-vite
pnpm add -D vite @vitejs/plugin-react

Bridges NestJS and Vite’s dev server so that HMR, React Fast Refresh, and the Vite manifest work transparently.

ExportDescription
nestInertia(options)Vite plugin — configures React/Vue/Svelte transforms + manifest
setupInertiaVite(app, options)Attaches Vite dev-server middleware to the NestJS app
vite.config.ts
import { defineConfig } from 'vite';
import { nestInertia } from '@dudousxd/nestjs-inertia-vite';
export default defineConfig({
plugins: [
nestInertia({
react: true, // also: vue: true | svelte: true
root: '.', // optional — defaults to 'inertia'
entry: 'inertia/app.tsx', // optional — defaults to 'inertia/app/client.tsx'
}),
],
// The plugin only sets root/input if you haven't already — your values win.
});

The root and entry options override the plugin’s defaults. If you set build.rollupOptions.input or root directly in your Vite config, those win — the plugin respects user overrides.

src/main.ts
import { setupInertiaVite } from '@dudousxd/nestjs-inertia-vite';
const app = await NestFactory.create(AppModule);
await setupInertiaVite(app, {
mode: process.env.NODE_ENV ?? 'development',
root: 'inertia', // Vite root (where index.html lives)
publicDir: 'dist/inertia/client',
outDir: 'dist/inertia',
});
await app.listen(3000);

In development, attaches Vite in middleware mode with HMR. In production, serves hashed assets from publicDir with long cache headers using the Vite manifest.