Webpack plugin
Configure the Webpack class adapter and understand its compiler hooks, dependencies, and watch recovery.
Install and configure
pnpm add -D @cookbook/router-webpack-pluginnpm install --save-dev @cookbook/router-webpack-pluginyarn add -D @cookbook/router-webpack-pluginbun add -d @cookbook/router-webpack-pluginimport CookbookRouterPlugin from '@cookbook/router-webpack-plugin';
export default {
plugins: [new CookbookRouterPlugin()],
};Named and default imports refer to the same class:
class CookbookRouterPlugin implements WebpackPluginInstance {
constructor(options?: CookbookRouterPluginOptions);
apply(compiler: Compiler): void;
}
interface CookbookRouterPluginOptions
extends CookbookRouterBuilderPluginOptions {}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.
Compiler lifecycle
The adapter delegates to applyRouterCompilerBuildHooks():
beforeRungenerates and fails a normal build on error.watchRungenerates, reports errors, preserves previous valid files, and lets watch mode continue.afterCompileadds current file, context, and missing dependencies.- The generated output directory is added to
watchOptions.ignoredwithout discarding existing ignore rules.
Missing dependencies matter. They allow Webpack to notice a config or route file that did not exist during the failed run.
Where this bites
Replacing compiler.options.watchOptions.ignored after plugin application can reintroduce output loops. Merge watch settings instead of overwriting them late.