Bun plugin
Run Cookbook Router generation from Bun onStart and understand the native watch limitation.
Install and configure
pnpm add -D @cookbook/router-bun-pluginnpm install --save-dev @cookbook/router-bun-pluginyarn add -D @cookbook/router-bun-pluginbun add -d @cookbook/router-bun-pluginimport { cookbookRouterBunPlugin } from '@cookbook/router-bun-plugin';
await Bun.build({
entrypoints: ['./src/main.tsx'],
plugins: [cookbookRouterBunPlugin()],
});function cookbookRouterBunPlugin(
options?: CookbookRouterBunPluginOptions,
): Bun.BunPlugin;
interface CookbookRouterBunPluginOptions
extends CookbookRouterBuilderPluginOptions {}The factory is exported by name and as the default export.
Shared build-runner options
All plugins except Vite extend CookbookRouterBuilderPluginOptions from @cookbook/router-cli.
Prop
Type
The runner resolves command options, generates physical artifacts, and then resolves watch paths even after a failure. That last part is the recovery mechanism: a bad config should not make the plugin blind to the file that can repair it.
Generated artifacts
A successful aggregate run writes:
contracts.tsregister.d.tsmanifest.json
It writes routes.ts only when the loaded route input contains statically composable route exports. JSON-only or otherwise non-composable input can still produce contracts and a manifest without producing a runtime route module.
Precedence
- Explicit plugin options
- Values from
cookbook-router.config.* - Framework defaults
An explicit routeFiles or outDir is not merged with the config value. It replaces it.
Lifecycle and errors
The plugin registers an asynchronous onStart callback. A failed runner result is converted to one Error containing the formatted Cookbook Router messages. Bun receives that thrown error and aborts the build.
Watch boundary
The adapter does not register arbitrary route roots. For development flows where creating or deleting a matching route must trigger generation, run cbr generate --watch as a companion process.