Cookbook Router

Vite plugin

Configure the named Vite adapter, its dev-server watcher, debounce behavior, and production failure semantics.

Install

pnpm add -D @cookbook/router-vite-plugin
npm install --save-dev @cookbook/router-vite-plugin
yarn add -D @cookbook/router-vite-plugin
bun add -d @cookbook/router-vite-plugin

Configure

vite.config.ts
import { defineConfig } from 'vite';
import { cookbookRouterVitePlugin } from '@cookbook/router-vite-plugin';

export default defineConfig({
  plugins: [cookbookRouterVitePlugin()],
});

There is no default export in the current package. Import the named factory.

Signature

interface CookbookRouterVitePluginOptions {
  readonly configFile?: string;
  readonly routeFiles?: string | readonly string[];
  readonly outDir?: string;
  readonly debounceMs?: number;
  readonly fs?: CliFileSystem;
}

function cookbookRouterVitePlugin(
  options?: CookbookRouterVitePluginOptions,
): Plugin;

Prop

Type

Vite does not expose cwd because the adapter uses the resolved Vite root.

Lifecycle

  • enforce: 'pre' makes generation run before normal application transformation.
  • buildStart generates before production compilation and throws when generation fails in build mode.
  • configureServer performs an initial generation before application modules are transformed.
  • The watcher tracks config candidates, resolved config, route roots/files, and the output directory.
  • Deleting a generated file triggers regeneration; successful recovery sends a full reload.
  • Output changes produced by the plugin are ignored to prevent self-triggered loops.

Error recovery

During development, failures are reported through the Vite logger. Watch paths are recalculated with fallback candidates, so fixing or creating the missing input triggers another run. A successful retry reloads the page.

Where this bites

Do not add the generated output directory as a separate application watch trigger. The plugin already watches it narrowly for deletion recovery and ignores normal generated writes.

On this page