Cookbook Router

Rspack plugin

Configure the Rspack class adapter, aliases, and shared compiler-hook behavior.

Install and configure

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

export default {
  plugins: [new CookbookRouterRspackPlugin()],
};

Exports

class CookbookRouterRspackPlugin implements RspackPluginInstance {
  constructor(options?: CookbookRouterRspackPluginOptions);
  apply(compiler: Compiler): void;
}

export { CookbookRouterRspackPlugin as CookbookRouterPlugin };
export default CookbookRouterRspackPlugin;

CookbookRouterPlugin is an alias, not a second implementation.

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 recovery

Rspack uses the same exported compiler-hook adapter as Webpack. Normal runs fail on bad generation. Watch runs report the error, keep the previous valid artifacts, register fallback dependencies, and retry after a relevant change.

Where this bites

Examples copied from Webpack are structurally similar, but import from the Rspack package. Mixing the packages can compile as configuration code and still hand the wrong plugin contract to the bundler.

On this page