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-pluginnpm install --save-dev @cookbook/router-rollup-pluginyarn add -D @cookbook/router-rollup-pluginbun add -d @cookbook/router-rollup-pluginimport { 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.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
On every buildStart, the plugin:
- Runs the shared build runner.
- Calls
addWatchFile()for every resolved or fallback watch path. - Returns on success.
- Warns on failure.
- 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.