Vite plugin
Configure the named Vite adapter, its dev-server watcher, debounce behavior, and production failure semantics.
Install
pnpm add -D @cookbook/router-vite-pluginnpm install --save-dev @cookbook/router-vite-pluginyarn add -D @cookbook/router-vite-pluginbun add -d @cookbook/router-vite-pluginConfigure
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.buildStartgenerates before production compilation and throws when generation fails in build mode.configureServerperforms 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.