Cookbook Router

Bun plugin

Run Cookbook Router generation from Bun onStart and understand the native watch limitation.

Install and configure

pnpm add -D @cookbook/router-bun-plugin
npm install --save-dev @cookbook/router-bun-plugin
yarn add -D @cookbook/router-bun-plugin
bun add -d @cookbook/router-bun-plugin
build.ts
import { 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.ts
  • register.d.ts
  • manifest.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

  1. Explicit plugin options
  2. Values from cookbook-router.config.*
  3. 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.

On this page