Cookbook Router

Rollup and Rolldown plugin

Run generation from the Rollup-compatible buildStart lifecycle and register route roots as watch files.

Install and configure

pnpm add -D @cookbook/router-rollup-plugin
npm install --save-dev @cookbook/router-rollup-plugin
yarn add -D @cookbook/router-rollup-plugin
bun add -d @cookbook/router-rollup-plugin
rollup.config.ts
import { cookbookRouterRollupPlugin } from '@cookbook/router-rollup-plugin';

export default {
  plugins: [cookbookRouterRollupPlugin()],
};
function cookbookRouterRollupPlugin(
  options?: CookbookRouterRollupPluginOptions,
): Plugin;

interface CookbookRouterRollupPluginOptions
  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

On every buildStart, the plugin:

  1. Runs the shared build runner.
  2. Calls addWatchFile() for every resolved or fallback watch path.
  3. Returns on success.
  4. Warns on failure.
  5. Keeps watch mode alive, but calls this.error() in a non-watch build.

Because watch paths are returned even after failure, a broken config can still recover when repaired.

Where this bites

The warning in watch mode is deliberate. Turning every transient route-edit error into a terminal Rollup failure would kill the process that is supposed to notice the fix.

On this page