@dudousxd/nestjs-inertia-vite 1.4.3 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,36 @@
1
1
  # Changelog — @dudousxd/nestjs-inertia-vite
2
2
 
3
+ ## 1.5.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#37](https://github.com/DavideCarvalho/nestjs-inertia/pull/37) [`605c1f7`](https://github.com/DavideCarvalho/nestjs-inertia/commit/605c1f78189664556001e3504614cebd9327e107) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Ship TanStack Intent agent skills (SKILL.md) inside the package.
8
+
9
+ ## 1.5.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#29](https://github.com/DavideCarvalho/nestjs-inertia/pull/29) [`7def22b`](https://github.com/DavideCarvalho/nestjs-inertia/commit/7def22b2df24a472f0e0bcef457aa3b1e60f9fe9) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - A broad set of ecosystem improvements across the server adapter, typed client, codegen, testing, and Vite packages.
14
+
15
+ **Server (`@dudousxd/nestjs-inertia`)**
16
+
17
+ - General flash messages: the flash store now carries arbitrary flash payloads (success, info, warning, etc.) instead of being limited to errors.
18
+ - Stable asset-version fallback: the asset-version provider derives a deterministic fallback version so SSR/CSR markup stays consistent when no explicit version is configured.
19
+ - `matchOn: string | string[]`: partial-reload / scope matching accepts either a single key or an array of keys.
20
+ - `lazy()` deprecation: deprecated usages now emit a warning through the Nest `Logger` to guide migration.
21
+ - SSR streaming: streaming SSR render is supported on both the Express and Fastify adapters, with a retryable SSR loader that falls back to buffered SSR when streaming setup fails.
22
+ - Packaging hygiene: dual ESM/CJS `exports` maps and build config cleaned up across the package set.
23
+
24
+ **Client (`@dudousxd/nestjs-inertia-client`)**
25
+
26
+ - Typed `useForm` end-to-end for React, Vue, and Svelte.
27
+ - Typed `<Deferred>` / `<WhenVisible>` components with shared deferred types across frameworks.
28
+ - Native `router.poll` and prefetch helpers (typed poll + prefetch-route utilities).
29
+
30
+ **Codegen, testing, and Vite**
31
+
32
+ - Codegen extension, testing helpers (Jest + Vitest), and the Vite plugin updated to support the new typed client surface and packaging conventions.
33
+
3
34
  ## 1.4.3
4
35
 
5
36
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -181,7 +181,7 @@ function nestInertia(options = {}) {
181
181
  __name(nestInertia, "nestInertia");
182
182
 
183
183
  // src/index.ts
184
- var VERSION = "1.4.3";
184
+ var VERSION = "1.5.1";
185
185
  // Annotate the CommonJS export names for ESM import in node:
186
186
  0 && (module.exports = {
187
187
  InvalidViteConfigException,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/setup.ts","../src/plugin/plugin.ts"],"sourcesContent":["export const VERSION = '1.4.3';\nexport { setupInertiaVite } from './setup.js';\nexport type { SetupInertiaViteOptions } from './setup.js';\nexport { default as nestInertia } from './plugin/plugin.js';\nexport type { NestInertiaPluginOptions } from './plugin/plugin.js';\nexport { InvalidViteConfigException } from './plugin/plugin.js';\n","import { resolve } from 'node:path';\n\nexport interface SetupInertiaViteOptions {\n mode: string | undefined;\n root: string;\n publicDir: string;\n outDir: string;\n hmrPort?: number;\n configFile?: string;\n}\n\ntype NestApp = {\n use: (pathOrMiddleware: unknown, middleware?: unknown) => void;\n};\n\nexport async function setupInertiaVite(\n app: NestApp,\n options: SetupInertiaViteOptions,\n): Promise<void> {\n if (options.mode !== 'production') {\n const { createServer: createViteServer } = await import('vite');\n const vite = await createViteServer({\n configFile: options.configFile ?? resolve(process.cwd(), 'vite.config.ts'),\n root: options.root,\n server: {\n middlewareMode: true,\n hmr: { port: options.hmrPort ?? 24679 },\n },\n appType: 'custom',\n });\n app.use((vite as { middlewares: unknown }).middlewares);\n return;\n }\n\n // Production: serve dist/<outDir>/client\n const express = await import('express');\n const clientDir = resolve(process.cwd(), options.outDir, 'client');\n app.use(\n '/assets',\n (express.default ?? express).static(resolve(clientDir, 'assets'), {\n maxAge: '1y',\n immutable: true,\n }),\n );\n app.use(\n (express.default ?? express).static(clientDir, {\n maxAge: '1h',\n index: false,\n fallthrough: true,\n }),\n );\n}\n","import { createRequire } from 'node:module';\nimport { resolve } from 'node:path';\nimport type { Plugin, UserConfig } from 'vite';\n\nconst require = createRequire(import.meta.url);\n\nexport interface NestInertiaPluginOptions {\n ssr?: boolean;\n react?: boolean;\n vue?: boolean;\n svelte?: boolean;\n /**\n * When `true`, the nestInertia plugin will skip auto-loading the framework\n * Vite plugin. Use this when the framework plugin (e.g. @sveltejs/vite-plugin-svelte)\n * needs to be added manually in the vite config alongside nestInertia().\n *\n * @default false\n */\n skipFrameworkPlugin?: boolean;\n clientEntry?: string;\n ssrEntry?: string;\n alias?: Record<string, string>;\n root?: string;\n entry?: string;\n}\n\nexport class InvalidViteConfigException extends Error {\n constructor(message: string) {\n super(`[nestjs-inertia-vite] ${message}`);\n this.name = 'InvalidViteConfigException';\n }\n}\n\nfunction loadFrameworkPlugin(framework: 'react' | 'vue' | 'svelte'): Plugin {\n const pkg =\n framework === 'react'\n ? '@vitejs/plugin-react'\n : framework === 'vue'\n ? '@vitejs/plugin-vue'\n : '@sveltejs/vite-plugin-svelte';\n try {\n const mod = require(pkg) as { default?: () => Plugin; svelte?: () => Plugin };\n // @sveltejs/vite-plugin-svelte v3+ exports a named `svelte` export rather than default\n const factory =\n mod.default ??\n (framework === 'svelte' ? mod.svelte : undefined) ??\n (mod as unknown as () => Plugin);\n return (factory as () => Plugin)();\n } catch {\n throw new InvalidViteConfigException(`Plugin \"${pkg}\" not installed. Run: pnpm add ${pkg}`);\n }\n}\n\nexport default function nestInertia(options: NestInertiaPluginOptions = {}): Plugin[] {\n const frameworkFlags = [options.react, options.vue, options.svelte].filter(Boolean);\n if (frameworkFlags.length !== 1) {\n throw new InvalidViteConfigException(\n 'nestInertia requires exactly one framework flag: react, vue, or svelte',\n );\n }\n\n const defaultRoot = 'inertia';\n const alias = {\n '@': resolve(process.cwd(), options.root ?? defaultRoot),\n ...(options.alias ?? {}),\n };\n\n const configurer: Plugin = {\n name: 'nestjs-inertia',\n config: (userConfig: UserConfig): Omit<UserConfig, 'plugins'> => {\n const resolvedRoot = options.root ?? defaultRoot;\n const defaultEntry = options.entry ?? options.clientEntry ?? `${resolvedRoot}/app/client.tsx`;\n\n const buildConfig: NonNullable<UserConfig['build']> = {\n manifest: true,\n rollupOptions: {},\n };\n\n // Only set outDir if the user hasn't already defined it\n if (!userConfig.build?.outDir) {\n buildConfig.outDir = 'dist/inertia/client';\n }\n\n // Only set rollupOptions.input if the user hasn't already defined it\n if (!userConfig.build?.rollupOptions?.input) {\n buildConfig.rollupOptions = {\n input: resolve(process.cwd(), defaultEntry),\n };\n }\n\n const result: Omit<UserConfig, 'plugins'> = {\n build: buildConfig,\n resolve: { alias },\n server: {\n middlewareMode: true,\n hmr: { port: 24679 },\n },\n };\n\n // Only set root if the user hasn't already defined it in their vite config\n if (!userConfig.root) {\n result.root = resolve(process.cwd(), resolvedRoot);\n }\n\n return result;\n },\n };\n\n const codegenHmr: Plugin = {\n name: 'nestjs-inertia:codegen-hmr',\n configureServer(server) {\n const codegenDir = resolve(process.cwd(), '.nestjs-inertia');\n const { watcher } = server;\n watcher.add(codegenDir);\n watcher.on('change', (file) => {\n if (!file.startsWith(codegenDir)) return;\n const mods = server.moduleGraph.getModulesByFile(file);\n if (mods) {\n for (const mod of mods) {\n server.moduleGraph.invalidateModule(mod);\n }\n }\n server.ws.send({ type: 'full-reload' });\n });\n },\n };\n\n if (options.skipFrameworkPlugin) {\n return [configurer, codegenHmr];\n }\n\n const frameworkPlugin = options.react\n ? loadFrameworkPlugin('react')\n : options.vue\n ? loadFrameworkPlugin('vue')\n : loadFrameworkPlugin('svelte');\n\n return [configurer, frameworkPlugin, codegenHmr];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;ACAA,uBAAwB;AAexB,eAAsBA,iBACpBC,KAC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AKP;AACpBO,cAAQC,IAAIF,UAAAA;AACZC,cAAQE,GAAG,UAAU,CAACC,SAAAA;AACpB,YAAI,CAACA,KAAKC,WAAWL,UAAAA,EAAa;AAClC,cAAMM,OAAOZ,OAAOa,YAAYC,iBAAiBJ,IAAAA;AACjD,YAAIE,MAAM;AACR,qBAAW5C,OAAO4C,MAAM;AACtBZ,mBAAOa,YAAYE,iBAAiB/C,GAAAA;UACtC;QACF;AACAgC,eAAOgB,GAAGC,KAAK;UAAEC,MAAM;QAAc,CAAA;MACvC,CAAA;IACF;EACF;AAEA,MAAI7C,QAAQ8C,qBAAqB;AAC/B,WAAO;MAACjC;MAAYkB;;EACtB;AAEA,QAAMgB,kBAAkB/C,QAAQE,QAC5BV,oBAAoB,OAAA,IACpBQ,QAAQG,MACNX,oBAAoB,KAAA,IACpBA,oBAAoB,QAAA;AAE1B,SAAO;IAACqB;IAAYkC;IAAiBhB;;AACvC;AArFwBiB;;;AFrDjB,IAAMC,UAAU;","names":["setupInertiaVite","app","options","mode","createServer","createViteServer","vite","configFile","resolve","process","cwd","root","server","middlewareMode","hmr","port","hmrPort","appType","use","middlewares","express","clientDir","outDir","default","static","maxAge","immutable","index","fallthrough","import_node_path","require","createRequire","InvalidViteConfigException","Error","message","name","loadFrameworkPlugin","framework","pkg","mod","factory","default","svelte","undefined","options","frameworkFlags","react","vue","filter","Boolean","length","defaultRoot","alias","resolve","process","cwd","root","configurer","config","userConfig","resolvedRoot","defaultEntry","entry","clientEntry","buildConfig","manifest","rollupOptions","build","outDir","input","result","server","middlewareMode","hmr","port","codegenHmr","configureServer","codegenDir","watcher","add","on","file","startsWith","mods","moduleGraph","getModulesByFile","invalidateModule","ws","send","type","skipFrameworkPlugin","frameworkPlugin","nestInertia","VERSION"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/setup.ts","../src/plugin/plugin.ts"],"sourcesContent":["export const VERSION = '1.5.1';\nexport { setupInertiaVite } from './setup.js';\nexport type { SetupInertiaViteOptions } from './setup.js';\nexport { default as nestInertia } from './plugin/plugin.js';\nexport type { NestInertiaPluginOptions } from './plugin/plugin.js';\nexport { InvalidViteConfigException } from './plugin/plugin.js';\n","import { resolve } from 'node:path';\n\nexport interface SetupInertiaViteOptions {\n mode: string | undefined;\n root: string;\n publicDir: string;\n outDir: string;\n hmrPort?: number;\n configFile?: string;\n}\n\ntype NestApp = {\n use: (pathOrMiddleware: unknown, middleware?: unknown) => void;\n};\n\nexport async function setupInertiaVite(\n app: NestApp,\n options: SetupInertiaViteOptions,\n): Promise<void> {\n if (options.mode !== 'production') {\n const { createServer: createViteServer } = await import('vite');\n const vite = await createViteServer({\n configFile: options.configFile ?? resolve(process.cwd(), 'vite.config.ts'),\n root: options.root,\n server: {\n middlewareMode: true,\n hmr: { port: options.hmrPort ?? 24679 },\n },\n appType: 'custom',\n });\n app.use((vite as { middlewares: unknown }).middlewares);\n return;\n }\n\n // Production: serve dist/<outDir>/client\n const express = await import('express');\n const clientDir = resolve(process.cwd(), options.outDir, 'client');\n app.use(\n '/assets',\n (express.default ?? express).static(resolve(clientDir, 'assets'), {\n maxAge: '1y',\n immutable: true,\n }),\n );\n app.use(\n (express.default ?? express).static(clientDir, {\n maxAge: '1h',\n index: false,\n fallthrough: true,\n }),\n );\n}\n","import { createRequire } from 'node:module';\nimport { resolve } from 'node:path';\nimport type { Plugin, UserConfig } from 'vite';\n\nconst require = createRequire(import.meta.url);\n\nexport interface NestInertiaPluginOptions {\n ssr?: boolean;\n react?: boolean;\n vue?: boolean;\n svelte?: boolean;\n /**\n * When `true`, the nestInertia plugin will skip auto-loading the framework\n * Vite plugin. Use this when the framework plugin (e.g. @sveltejs/vite-plugin-svelte)\n * needs to be added manually in the vite config alongside nestInertia().\n *\n * @default false\n */\n skipFrameworkPlugin?: boolean;\n clientEntry?: string;\n ssrEntry?: string;\n alias?: Record<string, string>;\n root?: string;\n entry?: string;\n}\n\nexport class InvalidViteConfigException extends Error {\n constructor(message: string) {\n super(`[nestjs-inertia-vite] ${message}`);\n this.name = 'InvalidViteConfigException';\n }\n}\n\nfunction loadFrameworkPlugin(framework: 'react' | 'vue' | 'svelte'): Plugin {\n const pkg =\n framework === 'react'\n ? '@vitejs/plugin-react'\n : framework === 'vue'\n ? '@vitejs/plugin-vue'\n : '@sveltejs/vite-plugin-svelte';\n try {\n const mod = require(pkg) as { default?: () => Plugin; svelte?: () => Plugin };\n // @sveltejs/vite-plugin-svelte v3+ exports a named `svelte` export rather than default\n const factory =\n mod.default ??\n (framework === 'svelte' ? mod.svelte : undefined) ??\n (mod as unknown as () => Plugin);\n return (factory as () => Plugin)();\n } catch {\n throw new InvalidViteConfigException(`Plugin \"${pkg}\" not installed. Run: pnpm add ${pkg}`);\n }\n}\n\nexport default function nestInertia(options: NestInertiaPluginOptions = {}): Plugin[] {\n const frameworkFlags = [options.react, options.vue, options.svelte].filter(Boolean);\n if (frameworkFlags.length !== 1) {\n throw new InvalidViteConfigException(\n 'nestInertia requires exactly one framework flag: react, vue, or svelte',\n );\n }\n\n const defaultRoot = 'inertia';\n const alias = {\n '@': resolve(process.cwd(), options.root ?? defaultRoot),\n ...(options.alias ?? {}),\n };\n\n const configurer: Plugin = {\n name: 'nestjs-inertia',\n config: (userConfig: UserConfig): Omit<UserConfig, 'plugins'> => {\n const resolvedRoot = options.root ?? defaultRoot;\n const defaultEntry = options.entry ?? options.clientEntry ?? `${resolvedRoot}/app/client.tsx`;\n\n const buildConfig: NonNullable<UserConfig['build']> = {\n manifest: true,\n rollupOptions: {},\n };\n\n // Only set outDir if the user hasn't already defined it\n if (!userConfig.build?.outDir) {\n buildConfig.outDir = 'dist/inertia/client';\n }\n\n // Only set rollupOptions.input if the user hasn't already defined it\n if (!userConfig.build?.rollupOptions?.input) {\n buildConfig.rollupOptions = {\n input: resolve(process.cwd(), defaultEntry),\n };\n }\n\n const result: Omit<UserConfig, 'plugins'> = {\n build: buildConfig,\n resolve: { alias },\n server: {\n middlewareMode: true,\n hmr: { port: 24679 },\n },\n };\n\n // Only set root if the user hasn't already defined it in their vite config\n if (!userConfig.root) {\n result.root = resolve(process.cwd(), resolvedRoot);\n }\n\n return result;\n },\n };\n\n const codegenHmr: Plugin = {\n name: 'nestjs-inertia:codegen-hmr',\n configureServer(server) {\n const codegenDir = resolve(process.cwd(), '.nestjs-inertia');\n const { watcher } = server;\n watcher.add(codegenDir);\n watcher.on('change', (file) => {\n if (!file.startsWith(codegenDir)) return;\n const mods = server.moduleGraph.getModulesByFile(file);\n if (mods) {\n for (const mod of mods) {\n server.moduleGraph.invalidateModule(mod);\n }\n }\n server.ws.send({ type: 'full-reload' });\n });\n },\n };\n\n if (options.skipFrameworkPlugin) {\n return [configurer, codegenHmr];\n }\n\n const frameworkPlugin = options.react\n ? loadFrameworkPlugin('react')\n : options.vue\n ? loadFrameworkPlugin('vue')\n : loadFrameworkPlugin('svelte');\n\n return [configurer, frameworkPlugin, codegenHmr];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;ACAA,uBAAwB;AAexB,eAAsBA,iBACpBC,KACAC,SAAgC;AAEhC,MAAIA,QAAQC,SAAS,cAAc;AACjC,UAAM,EAAEC,cAAcC,iBAAgB,IAAK,MAAM,OAAO,MAAA;AACxD,UAAMC,OAAO,MAAMD,iBAAiB;MAClCE,YAAYL,QAAQK,kBAAcC,0BAAQC,QAAQC,IAAG,GAAI,gBAAA;MACzDC,MAAMT,QAAQS;MACdC,QAAQ;QACNC,gBAAgB;QAChBC,KAAK;UAAEC,MAAMb,QAAQc,WAAW;QAAM;MACxC;MACAC,SAAS;IACX,CAAA;AACAhB,QAAIiB,IAAKZ,KAAkCa,WAAW;AACtD;EACF;AAGA,QAAMC,UAAU,MAAM,OAAO,SAAA;AAC7B,QAAMC,gBAAYb,0BAAQC,QAAQC,IAAG,GAAIR,QAAQoB,QAAQ,QAAA;AACzDrB,MAAIiB,IACF,YACCE,QAAQG,WAAWH,SAASI,WAAOhB,0BAAQa,WAAW,QAAA,G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B;;AACvC;AArFwBiB;;;AFrDjB,IAAMC,UAAU;","names":["setupInertiaVite","app","options","mode","createServer","createViteServer","vite","configFile","resolve","process","cwd","root","server","middlewareMode","hmr","port","hmrPort","appType","use","middlewares","express","clientDir","outDir","default","static","maxAge","immutable","index","fallthrough","import_node_path","require","createRequire","InvalidViteConfigException","Error","message","name","loadFrameworkPlugin","framework","pkg","mod","factory","default","svelte","undefined","options","frameworkFlags","react","vue","filter","Boolean","length","defaultRoot","alias","resolve","process","cwd","root","configurer","config","userConfig","resolvedRoot","defaultEntry","entry","clientEntry","buildConfig","manifest","rollupOptions","build","outDir","input","result","server","middlewareMode","hmr","port","codegenHmr","configureServer","codegenDir","watcher","add","on","file","startsWith","mods","moduleGraph","getModulesByFile","invalidateModule","ws","send","type","skipFrameworkPlugin","frameworkPlugin","nestInertia","VERSION"]}
@@ -0,0 +1,19 @@
1
+ export { InvalidViteConfigException, NestInertiaPluginOptions, default as nestInertia } from './plugin/plugin.cjs';
2
+ import 'vite';
3
+
4
+ interface SetupInertiaViteOptions {
5
+ mode: string | undefined;
6
+ root: string;
7
+ publicDir: string;
8
+ outDir: string;
9
+ hmrPort?: number;
10
+ configFile?: string;
11
+ }
12
+ type NestApp = {
13
+ use: (pathOrMiddleware: unknown, middleware?: unknown) => void;
14
+ };
15
+ declare function setupInertiaVite(app: NestApp, options: SetupInertiaViteOptions): Promise<void>;
16
+
17
+ declare const VERSION = "1.5.1";
18
+
19
+ export { type SetupInertiaViteOptions, VERSION, setupInertiaVite };
package/dist/index.d.ts CHANGED
@@ -14,6 +14,6 @@ type NestApp = {
14
14
  };
15
15
  declare function setupInertiaVite(app: NestApp, options: SetupInertiaViteOptions): Promise<void>;
16
16
 
17
- declare const VERSION = "1.4.3";
17
+ declare const VERSION = "1.5.1";
18
18
 
19
19
  export { type SetupInertiaViteOptions, VERSION, setupInertiaVite };
package/dist/index.js CHANGED
@@ -143,7 +143,7 @@ function nestInertia(options = {}) {
143
143
  __name(nestInertia, "nestInertia");
144
144
 
145
145
  // src/index.ts
146
- var VERSION = "1.4.3";
146
+ var VERSION = "1.5.1";
147
147
  export {
148
148
  InvalidViteConfigException,
149
149
  VERSION,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/setup.ts","../src/plugin/plugin.ts","../src/index.ts"],"sourcesContent":["import { resolve } from 'node:path';\n\nexport interface SetupInertiaViteOptions {\n mode: string | undefined;\n root: string;\n publicDir: string;\n outDir: string;\n hmrPort?: number;\n configFile?: string;\n}\n\ntype NestApp = {\n use: (pathOrMiddleware: unknown, middleware?: unknown) => void;\n};\n\nexport async function setupInertiaVite(\n app: NestApp,\n options: SetupInertiaViteOptions,\n): Promise<void> {\n if (options.mode !== 'production') {\n const { createServer: createViteServer } = await import('vite');\n const vite = await createViteServer({\n configFile: options.configFile ?? resolve(process.cwd(), 'vite.config.ts'),\n root: options.root,\n server: {\n middlewareMode: true,\n hmr: { port: options.hmrPort ?? 24679 },\n },\n appType: 'custom',\n });\n app.use((vite as { middlewares: unknown }).middlewares);\n return;\n }\n\n // Production: serve dist/<outDir>/client\n const express = await import('express');\n const clientDir = resolve(process.cwd(), options.outDir, 'client');\n app.use(\n '/assets',\n (express.default ?? express).static(resolve(clientDir, 'assets'), {\n maxAge: '1y',\n immutable: true,\n }),\n );\n app.use(\n (express.default ?? express).static(clientDir, {\n maxAge: '1h',\n index: false,\n fallthrough: true,\n }),\n );\n}\n","import { createRequire } from 'node:module';\nimport { resolve } from 'node:path';\nimport type { Plugin, UserConfig } from 'vite';\n\nconst require = createRequire(import.meta.url);\n\nexport interface NestInertiaPluginOptions {\n ssr?: boolean;\n react?: boolean;\n vue?: boolean;\n svelte?: boolean;\n /**\n * When `true`, the nestInertia plugin will skip auto-loading the framework\n * Vite plugin. Use this when the framework plugin (e.g. @sveltejs/vite-plugin-svelte)\n * needs to be added manually in the vite config alongside nestInertia().\n *\n * @default false\n */\n skipFrameworkPlugin?: boolean;\n clientEntry?: string;\n ssrEntry?: string;\n alias?: Record<string, string>;\n root?: string;\n entry?: string;\n}\n\nexport class InvalidViteConfigException extends Error {\n constructor(message: string) {\n super(`[nestjs-inertia-vite] ${message}`);\n this.name = 'InvalidViteConfigException';\n }\n}\n\nfunction loadFrameworkPlugin(framework: 'react' | 'vue' | 'svelte'): Plugin {\n const pkg =\n framework === 'react'\n ? '@vitejs/plugin-react'\n : framework === 'vue'\n ? '@vitejs/plugin-vue'\n : '@sveltejs/vite-plugin-svelte';\n try {\n const mod = require(pkg) as { default?: () => Plugin; svelte?: () => Plugin };\n // @sveltejs/vite-plugin-svelte v3+ exports a named `svelte` export rather than default\n const factory =\n mod.default ??\n (framework === 'svelte' ? mod.svelte : undefined) ??\n (mod as unknown as () => Plugin);\n return (factory as () => Plugin)();\n } catch {\n throw new InvalidViteConfigException(`Plugin \"${pkg}\" not installed. Run: pnpm add ${pkg}`);\n }\n}\n\nexport default function nestInertia(options: NestInertiaPluginOptions = {}): Plugin[] {\n const frameworkFlags = [options.react, options.vue, options.svelte].filter(Boolean);\n if (frameworkFlags.length !== 1) {\n throw new InvalidViteConfigException(\n 'nestInertia requires exactly one framework flag: react, vue, or svelte',\n );\n }\n\n const defaultRoot = 'inertia';\n const alias = {\n '@': resolve(process.cwd(), options.root ?? defaultRoot),\n ...(options.alias ?? {}),\n };\n\n const configurer: Plugin = {\n name: 'nestjs-inertia',\n config: (userConfig: UserConfig): Omit<UserConfig, 'plugins'> => {\n const resolvedRoot = options.root ?? defaultRoot;\n const defaultEntry = options.entry ?? options.clientEntry ?? `${resolvedRoot}/app/client.tsx`;\n\n const buildConfig: NonNullable<UserConfig['build']> = {\n manifest: true,\n rollupOptions: {},\n };\n\n // Only set outDir if the user hasn't already defined it\n if (!userConfig.build?.outDir) {\n buildConfig.outDir = 'dist/inertia/client';\n }\n\n // Only set rollupOptions.input if the user hasn't already defined it\n if (!userConfig.build?.rollupOptions?.input) {\n buildConfig.rollupOptions = {\n input: resolve(process.cwd(), defaultEntry),\n };\n }\n\n const result: Omit<UserConfig, 'plugins'> = {\n build: buildConfig,\n resolve: { alias },\n server: {\n middlewareMode: true,\n hmr: { port: 24679 },\n },\n };\n\n // Only set root if the user hasn't already defined it in their vite config\n if (!userConfig.root) {\n result.root = resolve(process.cwd(), resolvedRoot);\n }\n\n return result;\n },\n };\n\n const codegenHmr: Plugin = {\n name: 'nestjs-inertia:codegen-hmr',\n configureServer(server) {\n const codegenDir = resolve(process.cwd(), '.nestjs-inertia');\n const { watcher } = server;\n watcher.add(codegenDir);\n watcher.on('change', (file) => {\n if (!file.startsWith(codegenDir)) return;\n const mods = server.moduleGraph.getModulesByFile(file);\n if (mods) {\n for (const mod of mods) {\n server.moduleGraph.invalidateModule(mod);\n }\n }\n server.ws.send({ type: 'full-reload' });\n });\n },\n };\n\n if (options.skipFrameworkPlugin) {\n return [configurer, codegenHmr];\n }\n\n const frameworkPlugin = options.react\n ? loadFrameworkPlugin('react')\n : options.vue\n ? loadFrameworkPlugin('vue')\n : loadFrameworkPlugin('svelte');\n\n return [configurer, frameworkPlugin, codegenHmr];\n}\n","export const VERSION = '1.4.3';\nexport { setupInertiaVite } from './setup.js';\nexport type { SetupInertiaViteOptions } from './setup.js';\nexport { default as nestInertia } from './plugin/plugin.js';\nexport type { NestInertiaPluginOptions } from './plugin/plugin.js';\nexport { InvalidViteConfigException } from './plugin/plugin.js';\n"],"mappings":";;;;AAAA,SAASA,eAAe;AAexB,eAAsBC,iBACpBC,KACAC,SAAgC;AAEhC,MAAIA,QAAQC,SAAS,cAAc;AACjC,UAAM,EAAEC,cAAcC,iBAAgB,IAAK,MAAM,OAAO,MAAA;AACxD,UAAMC,OAAO,MAAMD,iBAAiB;MAClCE,YAAYL,QAAQK,cAAcC,QAAQC,QAAQC,IAAG,GAAI,gBAAA;MACzDC,MAAMT,QAAQS;MACdC,QAAQ;QACNC,gBAAgB;QAChBC,KAAK;UAAEC,MAAMb,QAAQc,WAAW;QAAM;MACxC;MACAC,SAAS;IACX,CAAA;AAC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AA;MACvC,CAAA;IACF;EACF;AAEA,MAAI7C,QAAQ8C,qBAAqB;AAC/B,WAAO;MAACjC;MAAYkB;;EACtB;AAEA,QAAMgB,kBAAkB/C,QAAQE,QAC5BV,oBAAoB,OAAA,IACpBQ,QAAQG,MACNX,oBAAoB,KAAA,IACpBA,oBAAoB,QAAA;AAE1B,SAAO;IAACqB;IAAYkC;IAAiBhB;;AACvC;AArFwBiB;;;ACrDjB,IAAMC,UAAU;","names":["resolve","setupInertiaVite","app","options","mode","createServer","createViteServer","vite","configFile","resolve","process","cwd","root","server","middlewareMode","hmr","port","hmrPort","appType","use","middlewares","express","clientDir","outDir","default","static","maxAge","immutable","index","fallthrough","createRequire","resolve","require","createRequire","url","InvalidViteConfigException","Error","message","name","loadFrameworkPlugin","framework","pkg","mod","factory","default","svelte","undefined","options","frameworkFlags","react","vue","filter","Boolean","length","defaultRoot","alias","resolve","process","cwd","root","configurer","config","userConfig","resolvedRoot","defaultEntry","entry","clientEntry","buildConfig","manifest","rollupOptions","build","outDir","input","result","server","middlewareMode","hmr","port","codegenHmr","configureServer","codegenDir","watcher","add","on","file","startsWith","mods","moduleGraph","getModulesByFile","invalidateModule","ws","send","type","skipFrameworkPlugin","frameworkPlugin","nestInertia","VERSION"]}
1
+ {"version":3,"sources":["../src/setup.ts","../src/plugin/plugin.ts","../src/index.ts"],"sourcesContent":["import { resolve } from 'node:path';\n\nexport interface SetupInertiaViteOptions {\n mode: string | undefined;\n root: string;\n publicDir: string;\n outDir: string;\n hmrPort?: number;\n configFile?: string;\n}\n\ntype NestApp = {\n use: (pathOrMiddleware: unknown, middleware?: unknown) => void;\n};\n\nexport async function setupInertiaVite(\n app: NestApp,\n options: SetupInertiaViteOptions,\n): Promise<void> {\n if (options.mode !== 'production') {\n const { createServer: createViteServer } = await import('vite');\n const vite = await createViteServer({\n configFile: options.configFile ?? resolve(process.cwd(), 'vite.config.ts'),\n root: options.root,\n server: {\n middlewareMode: true,\n hmr: { port: options.hmrPort ?? 24679 },\n },\n appType: 'custom',\n });\n app.use((vite as { middlewares: unknown }).middlewares);\n return;\n }\n\n // Production: serve dist/<outDir>/client\n const express = await import('express');\n const clientDir = resolve(process.cwd(), options.outDir, 'client');\n app.use(\n '/assets',\n (express.default ?? express).static(resolve(clientDir, 'assets'), {\n maxAge: '1y',\n immutable: true,\n }),\n );\n app.use(\n (express.default ?? express).static(clientDir, {\n maxAge: '1h',\n index: false,\n fallthrough: true,\n }),\n );\n}\n","import { createRequire } from 'node:module';\nimport { resolve } from 'node:path';\nimport type { Plugin, UserConfig } from 'vite';\n\nconst require = createRequire(import.meta.url);\n\nexport interface NestInertiaPluginOptions {\n ssr?: boolean;\n react?: boolean;\n vue?: boolean;\n svelte?: boolean;\n /**\n * When `true`, the nestInertia plugin will skip auto-loading the framework\n * Vite plugin. Use this when the framework plugin (e.g. @sveltejs/vite-plugin-svelte)\n * needs to be added manually in the vite config alongside nestInertia().\n *\n * @default false\n */\n skipFrameworkPlugin?: boolean;\n clientEntry?: string;\n ssrEntry?: string;\n alias?: Record<string, string>;\n root?: string;\n entry?: string;\n}\n\nexport class InvalidViteConfigException extends Error {\n constructor(message: string) {\n super(`[nestjs-inertia-vite] ${message}`);\n this.name = 'InvalidViteConfigException';\n }\n}\n\nfunction loadFrameworkPlugin(framework: 'react' | 'vue' | 'svelte'): Plugin {\n const pkg =\n framework === 'react'\n ? '@vitejs/plugin-react'\n : framework === 'vue'\n ? '@vitejs/plugin-vue'\n : '@sveltejs/vite-plugin-svelte';\n try {\n const mod = require(pkg) as { default?: () => Plugin; svelte?: () => Plugin };\n // @sveltejs/vite-plugin-svelte v3+ exports a named `svelte` export rather than default\n const factory =\n mod.default ??\n (framework === 'svelte' ? mod.svelte : undefined) ??\n (mod as unknown as () => Plugin);\n return (factory as () => Plugin)();\n } catch {\n throw new InvalidViteConfigException(`Plugin \"${pkg}\" not installed. Run: pnpm add ${pkg}`);\n }\n}\n\nexport default function nestInertia(options: NestInertiaPluginOptions = {}): Plugin[] {\n const frameworkFlags = [options.react, options.vue, options.svelte].filter(Boolean);\n if (frameworkFlags.length !== 1) {\n throw new InvalidViteConfigException(\n 'nestInertia requires exactly one framework flag: react, vue, or svelte',\n );\n }\n\n const defaultRoot = 'inertia';\n const alias = {\n '@': resolve(process.cwd(), options.root ?? defaultRoot),\n ...(options.alias ?? {}),\n };\n\n const configurer: Plugin = {\n name: 'nestjs-inertia',\n config: (userConfig: UserConfig): Omit<UserConfig, 'plugins'> => {\n const resolvedRoot = options.root ?? defaultRoot;\n const defaultEntry = options.entry ?? options.clientEntry ?? `${resolvedRoot}/app/client.tsx`;\n\n const buildConfig: NonNullable<UserConfig['build']> = {\n manifest: true,\n rollupOptions: {},\n };\n\n // Only set outDir if the user hasn't already defined it\n if (!userConfig.build?.outDir) {\n buildConfig.outDir = 'dist/inertia/client';\n }\n\n // Only set rollupOptions.input if the user hasn't already defined it\n if (!userConfig.build?.rollupOptions?.input) {\n buildConfig.rollupOptions = {\n input: resolve(process.cwd(), defaultEntry),\n };\n }\n\n const result: Omit<UserConfig, 'plugins'> = {\n build: buildConfig,\n resolve: { alias },\n server: {\n middlewareMode: true,\n hmr: { port: 24679 },\n },\n };\n\n // Only set root if the user hasn't already defined it in their vite config\n if (!userConfig.root) {\n result.root = resolve(process.cwd(), resolvedRoot);\n }\n\n return result;\n },\n };\n\n const codegenHmr: Plugin = {\n name: 'nestjs-inertia:codegen-hmr',\n configureServer(server) {\n const codegenDir = resolve(process.cwd(), '.nestjs-inertia');\n const { watcher } = server;\n watcher.add(codegenDir);\n watcher.on('change', (file) => {\n if (!file.startsWith(codegenDir)) return;\n const mods = server.moduleGraph.getModulesByFile(file);\n if (mods) {\n for (const mod of mods) {\n server.moduleGraph.invalidateModule(mod);\n }\n }\n server.ws.send({ type: 'full-reload' });\n });\n },\n };\n\n if (options.skipFrameworkPlugin) {\n return [configurer, codegenHmr];\n }\n\n const frameworkPlugin = options.react\n ? loadFrameworkPlugin('react')\n : options.vue\n ? loadFrameworkPlugin('vue')\n : loadFrameworkPlugin('svelte');\n\n return [configurer, frameworkPlugin, codegenHmr];\n}\n","export const VERSION = '1.5.1';\nexport { setupInertiaVite } from './setup.js';\nexport type { SetupInertiaViteOptions } from './setup.js';\nexport { default as nestInertia } from './plugin/plugin.js';\nexport type { NestInertiaPluginOptions } from './plugin/plugin.js';\nexport { InvalidViteConfigException } from './plugin/plugin.js';\n"],"mappings":";;;;AAAA,SAASA,eAAe;AAexB,eAAsBC,iBACpBC,KACAC,SAAgC;AAEhC,MAAIA,QAAQC,SAAS,cAAc;AACjC,UAAM,EAAEC,cAAcC,iBAAgB,IAAK,MAAM,OAAO,MAAA;AACxD,UAAMC,OAAO,MAAMD,iBAAiB;MAClCE,YAAYL,QAAQK,cAAcC,QAAQC,QAAQC,IAAG,GAAI,gBAAA;MACzDC,MAAMT,QAAQS;MACdC,QAAQ;QACNC,gBAAgB;QAChBC,KAAK;UAAEC,MAAMb,QAAQc,WAAW;QAAM;MACxC;MACAC,SAAS;IACX,CAAA;AACAhB,QAAIiB,IAAKZ,KAAkCa,WAAW;AACtD;EACF;AAGA,QAAMC,UAAU,MAAM,OAAO,SAAA;AAC7B,QAAMC,YAAYb,QAAQC,QAAQC,IAAG,GAAIR,QAAQoB,QAAQ,QAAA;AACzDrB,MAAIiB,IACF,YACCE,QAAQG,WAAWH,SAASI,OAAOhB,QAAQa,WAAW,QAAA,GAAW;IAChEI,QAAQ;IACRC,WAAW;EACb,CAAA,CAAA;AAEFzB,MAAIiB,KACDE,QAAQG,WAAWH,SAASI,OAAOH,WAAW;IAC7CI,QAAQ;IACRE,OAAO;IACPC,aAAa;EACf,CAAA,CAAA;AAEJ;AApCsB5B;;;ACftB,SAAS6B,qBAAqB;AAC9B,SAASC,WAAAA,gBAAe;AAGxB,IAAMC,WAAUC,cAAc,YAAYC,GAAG;AAsBtC,IAAMC,6BAAN,cAAyCC,MAAAA;EA1BhD,OA0BgDA;;;EAC9C,YAAYC,SAAiB;AAC3B,UAAM,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ChBC,KAAK;YAAEC,MAAM;UAAM;QACrB;MACF;AAGA,UAAI,CAACf,WAAWH,MAAM;AACpBc,eAAOd,OAAOH,SAAQC,QAAQC,IAAG,GAAIK,YAAAA;MACvC;AAEA,aAAOU;IACT,GApCQ;EAqCV;AAEA,QAAMK,aAAqB;IACzBxC,MAAM;IACNyC,gBAAgBL,QAAM;AACpB,YAAMM,aAAaxB,SAAQC,QAAQC,IAAG,GAAI,iBAAA;AAC1C,YAAM,EAAEuB,QAAO,IAAKP;AACpBO,cAAQC,IAAIF,UAAAA;AACZC,cAAQE,GAAG,UAAU,CAACC,SAAAA;AACpB,YAAI,CAACA,KAAKC,WAAWL,UAAAA,EAAa;AAClC,cAAMM,OAAOZ,OAAOa,YAAYC,iBAAiBJ,IAAAA;AACjD,YAAIE,MAAM;AACR,qBAAW5C,OAAO4C,MAAM;AACtBZ,mBAAOa,YAAYE,iBAAiB/C,GAAAA;UACtC;QACF;AACAgC,eAAOgB,GAAGC,KAAK;UAAEC,MAAM;QAAc,CAAA;MACvC,CAAA;IACF;EACF;AAEA,MAAI7C,QAAQ8C,qBAAqB;AAC/B,WAAO;MAACjC;MAAYkB;;EACtB;AAEA,QAAMgB,kBAAkB/C,QAAQE,QAC5BV,oBAAoB,OAAA,IACpBQ,QAAQG,MACNX,oBAAoB,KAAA,IACpBA,oBAAoB,QAAA;AAE1B,SAAO;IAACqB;IAAYkC;IAAiBhB;;AACvC;AArFwBiB;;;ACrDjB,IAAMC,UAAU;","names":["resolve","setupInertiaVite","app","options","mode","createServer","createViteServer","vite","configFile","resolve","process","cwd","root","server","middlewareMode","hmr","port","hmrPort","appType","use","middlewares","express","clientDir","outDir","default","static","maxAge","immutable","index","fallthrough","createRequire","resolve","require","createRequire","url","InvalidViteConfigException","Error","message","name","loadFrameworkPlugin","framework","pkg","mod","factory","default","svelte","undefined","options","frameworkFlags","react","vue","filter","Boolean","length","defaultRoot","alias","resolve","process","cwd","root","configurer","config","userConfig","resolvedRoot","defaultEntry","entry","clientEntry","buildConfig","manifest","rollupOptions","build","outDir","input","result","server","middlewareMode","hmr","port","codegenHmr","configureServer","codegenDir","watcher","add","on","file","startsWith","mods","moduleGraph","getModulesByFile","invalidateModule","ws","send","type","skipFrameworkPlugin","frameworkPlugin","nestInertia","VERSION"]}
@@ -0,0 +1,27 @@
1
+ import { Plugin } from 'vite';
2
+
3
+ interface NestInertiaPluginOptions {
4
+ ssr?: boolean;
5
+ react?: boolean;
6
+ vue?: boolean;
7
+ svelte?: boolean;
8
+ /**
9
+ * When `true`, the nestInertia plugin will skip auto-loading the framework
10
+ * Vite plugin. Use this when the framework plugin (e.g. @sveltejs/vite-plugin-svelte)
11
+ * needs to be added manually in the vite config alongside nestInertia().
12
+ *
13
+ * @default false
14
+ */
15
+ skipFrameworkPlugin?: boolean;
16
+ clientEntry?: string;
17
+ ssrEntry?: string;
18
+ alias?: Record<string, string>;
19
+ root?: string;
20
+ entry?: string;
21
+ }
22
+ declare class InvalidViteConfigException extends Error {
23
+ constructor(message: string);
24
+ }
25
+ declare function nestInertia(options?: NestInertiaPluginOptions): Plugin[];
26
+
27
+ export { InvalidViteConfigException, type NestInertiaPluginOptions, nestInertia as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dudousxd/nestjs-inertia-vite",
3
- "version": "1.4.3",
3
+ "version": "1.5.1",
4
4
  "description": "Vite integration for @dudousxd/nestjs-inertia — dev middleware, prod static serving, plugin.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -15,23 +15,35 @@
15
15
  "types": "./dist/index.d.ts",
16
16
  "exports": {
17
17
  ".": {
18
- "types": "./dist/index.d.ts",
19
- "import": "./dist/index.js",
20
- "require": "./dist/index.cjs"
18
+ "import": {
19
+ "types": "./dist/index.d.ts",
20
+ "default": "./dist/index.js"
21
+ },
22
+ "require": {
23
+ "types": "./dist/index.d.cts",
24
+ "default": "./dist/index.cjs"
25
+ }
21
26
  },
22
27
  "./plugin": {
23
- "types": "./dist/plugin/plugin.d.ts",
24
- "import": "./dist/plugin/plugin.js",
25
- "require": "./dist/plugin/plugin.cjs"
28
+ "import": {
29
+ "types": "./dist/plugin/plugin.d.ts",
30
+ "default": "./dist/plugin/plugin.js"
31
+ },
32
+ "require": {
33
+ "types": "./dist/plugin/plugin.d.cts",
34
+ "default": "./dist/plugin/plugin.cjs"
35
+ }
26
36
  }
27
37
  },
38
+ "sideEffects": false,
28
39
  "files": [
29
40
  "dist/",
30
41
  "README.md",
31
- "CHANGELOG.md"
42
+ "CHANGELOG.md",
43
+ "skills"
32
44
  ],
33
45
  "peerDependencies": {
34
- "@dudousxd/nestjs-inertia": ">=1.4.2",
46
+ "@dudousxd/nestjs-inertia": ">=1.4.5",
35
47
  "@nestjs/common": ">=10.0.0",
36
48
  "@nestjs/core": ">=10.0.0",
37
49
  "vite": ">=5.0.0",
@@ -58,13 +70,16 @@
58
70
  "@vitejs/plugin-react": "^4.3.0",
59
71
  "express": "^4.19.2",
60
72
  "typescript": "^5.4.0",
61
- "vite": "^6.4.2",
62
- "vitest": "^3.0.0",
63
- "@dudousxd/nestjs-inertia": "1.4.2"
73
+ "vite": "^7.0.0",
74
+ "vitest": "^4.1.0",
75
+ "@dudousxd/nestjs-inertia": "1.8.1"
64
76
  },
65
77
  "engines": {
66
78
  "node": ">=20"
67
79
  },
80
+ "keywords": [
81
+ "tanstack-intent"
82
+ ],
68
83
  "scripts": {
69
84
  "build": "tsup",
70
85
  "test": "vitest run",
@@ -0,0 +1,155 @@
1
+ ---
2
+ name: inertia-vite-setup
3
+ description: >-
4
+ Vite dev/build glue for @dudousxd/nestjs-inertia-vite. Covers setupInertiaVite
5
+ (middleware-mode dev server + production static serving of dist/<outDir>/client)
6
+ and the nestInertia() Vite plugin (exactly one of react/vue/svelte flags,
7
+ manifest build, codegen HMR, root/entry/alias/outDir config, skipFrameworkPlugin),
8
+ plus InvalidViteConfigException. Use when wiring Vite HMR into a NestJS server,
9
+ configuring vite.config for an Inertia front end, or building client assets.
10
+ license: MIT
11
+ metadata:
12
+ type: core
13
+ library: "@dudousxd/nestjs-inertia-vite"
14
+ library_version: 1.5.0
15
+ framework: nestjs
16
+ ---
17
+
18
+ # Inertia Vite setup
19
+
20
+ `@dudousxd/nestjs-inertia-vite` has two halves: `setupInertiaVite(app, options)`
21
+ runs inside your NestJS bootstrap to mount Vite in middleware mode (dev) or serve
22
+ built assets (prod), and `nestInertia()` is the Vite plugin you add to
23
+ `vite.config.ts` to build the Inertia client (and optionally SSR) bundle.
24
+
25
+ ## Setup
26
+
27
+ ```bash
28
+ pnpm add -D @dudousxd/nestjs-inertia-vite vite
29
+ pnpm add -D @vitejs/plugin-react # or @vitejs/plugin-vue / @sveltejs/vite-plugin-svelte
30
+ ```
31
+
32
+ Server bootstrap (Express, middleware mode in dev):
33
+
34
+ ```ts
35
+ // main.ts
36
+ import { NestFactory } from '@nestjs/core';
37
+ import { setupInertiaVite } from '@dudousxd/nestjs-inertia-vite';
38
+ import { AppModule } from './app.module';
39
+
40
+ async function bootstrap() {
41
+ const app = await NestFactory.create(AppModule);
42
+ await setupInertiaVite(app, {
43
+ mode: process.env.NODE_ENV,
44
+ root: 'inertia',
45
+ publicDir: 'public',
46
+ outDir: 'dist/inertia',
47
+ });
48
+ await app.listen(3000);
49
+ }
50
+ bootstrap();
51
+ ```
52
+
53
+ `vite.config.ts`:
54
+
55
+ ```ts
56
+ import { defineConfig } from 'vite';
57
+ import nestInertia from '@dudousxd/nestjs-inertia-vite';
58
+
59
+ export default defineConfig({
60
+ plugins: [nestInertia({ react: true })],
61
+ });
62
+ ```
63
+
64
+ `Source: packages/vite/src/setup.ts, packages/vite/src/plugin/plugin.ts, packages/vite/src/index.ts`
65
+
66
+ ## Core patterns
67
+
68
+ ### 1. setupInertiaVite — dev vs prod branch
69
+
70
+ When `options.mode !== 'production'`, it creates a Vite server in
71
+ `middlewareMode` (HMR on port `hmrPort ?? 24679`) and mounts `vite.middlewares`.
72
+ In production it serves `dist/<outDir>/client` statically — `/assets` with a
73
+ 1-year immutable cache, the rest with a 1-hour cache. The `mode` you pass is the
74
+ ONLY switch between the two paths. `Source: packages/vite/src/setup.ts`
75
+
76
+ ### 2. nestInertia plugin — one framework, sensible defaults
77
+
78
+ ```ts
79
+ nestInertia({
80
+ react: true, // exactly one of react | vue | svelte
81
+ root: 'inertia', // alias '@' → <cwd>/inertia
82
+ entry: 'inertia/app/client.tsx',
83
+ ssr: true,
84
+ });
85
+ ```
86
+
87
+ The plugin returns an array: a config plugin (`manifest: true`, default
88
+ `outDir: 'dist/inertia/client'`, rollup input from `entry`/`clientEntry`), the
89
+ framework plugin (auto-loaded), and a codegen-HMR plugin that watches
90
+ `.nestjs-inertia/` and triggers a full reload when generated files change. It
91
+ only sets `root`/`outDir`/`input` when you have not already defined them.
92
+ `Source: packages/vite/src/plugin/plugin.ts`
93
+
94
+ ### 3. Bringing your own framework plugin
95
+
96
+ ```ts
97
+ import { svelte } from '@sveltejs/vite-plugin-svelte';
98
+
99
+ export default defineConfig({
100
+ plugins: [nestInertia({ svelte: true, skipFrameworkPlugin: true }), svelte()],
101
+ });
102
+ ```
103
+
104
+ `skipFrameworkPlugin: true` makes `nestInertia` return only the configurer +
105
+ codegen-HMR plugins, so you add the framework plugin yourself.
106
+ `Source: packages/vite/src/plugin/plugin.ts (skipFrameworkPlugin branch)`
107
+
108
+ ## Common mistakes
109
+
110
+ ### Mistake 1: passing zero or multiple framework flags
111
+
112
+ ```ts
113
+ // Wrong: both react and vue → throws InvalidViteConfigException at config load
114
+ nestInertia({ react: true, vue: true });
115
+ ```
116
+
117
+ ```ts
118
+ // Correct: exactly one framework flag
119
+ nestInertia({ react: true });
120
+ ```
121
+
122
+ Mechanism: the plugin counts truthy framework flags and throws unless exactly one
123
+ is set. `Source: packages/vite/src/plugin/plugin.ts (frameworkFlags.length !== 1)`
124
+
125
+ ### Mistake 2: omitting the framework plugin dependency
126
+
127
+ ```ts
128
+ // Wrong: nestInertia({ react: true }) but @vitejs/plugin-react not installed
129
+ // → InvalidViteConfigException: Plugin "@vitejs/plugin-react" not installed
130
+ ```
131
+
132
+ ```bash
133
+ # Correct: install the matching framework plugin (auto-loaded by nestInertia)
134
+ pnpm add -D @vitejs/plugin-react
135
+ ```
136
+
137
+ Mechanism: `loadFrameworkPlugin` `require()`s the framework package and rethrows
138
+ as `InvalidViteConfigException` with the install command when it is missing.
139
+ `Source: packages/vite/src/plugin/plugin.ts (loadFrameworkPlugin)`
140
+
141
+ ### Mistake 3: forgetting that the dev/prod switch is `mode`
142
+
143
+ ```ts
144
+ // Wrong: leaving mode undefined in production → falls into the dev Vite branch
145
+ await setupInertiaVite(app, { mode: undefined, root: 'inertia', publicDir: 'public', outDir: 'dist/inertia' });
146
+ ```
147
+
148
+ ```ts
149
+ // Correct: pass the real mode so prod serves built static assets
150
+ await setupInertiaVite(app, { mode: process.env.NODE_ENV, root: 'inertia', publicDir: 'public', outDir: 'dist/inertia' });
151
+ ```
152
+
153
+ Mechanism: the prod static-serving branch runs only when `mode === 'production'`;
154
+ any other value (including `undefined`) starts an in-process Vite dev server.
155
+ `Source: packages/vite/src/setup.ts (if options.mode !== 'production')`