Skip to content
Build tools

Build tool plugins

Run your kubb.config.ts from Vite, webpack, Rollup, Rolldown, Rspack, esbuild, Farm, Nuxt, or Astro with unplugin-kubb, so every build generates code from your API spec.

unplugin-kubb runs your kubb.config.ts when a build starts. It ships with kubb, and you import it from kubb/<tool>.

build startsload kubb.config.tsgeneratefiles writtenbuild continuesBuild toolunplugin-kubbKubbBuild toolunplugin-kubbKubb
Vite, Nuxt, and Astro generate during builds only, not in their dev servers. Run kubb generate before you start a dev server.

Each tool page passes your kubb.config.ts as config. Without config, the plugin finds kubb.config.ts like the CLI does and builds every config in it that has an input.

ToolImportConfig file
Vitekubb/vitevite.config.ts
webpackkubb/webpackwebpack.config.ts
Rspackkubb/rspackrspack.config.ts
Rollupkubb/rolluprollup.config.ts
Rolldownkubb/rolldownrolldown.config.ts
esbuildkubb/esbuildbuild.ts
Farmkubb/farmfarm.config.ts
Nuxtkubb/nuxtnuxt.config.ts
Astrokubb/astroastro.config.mjs

How the build runs Kubb

  • The plugin applies the same defaults as defineConfig and runs output.format, output.lint, and output.postGenerate.
  • It prints the run summary, not the json, file, or html reports. Use kubb generate for those.
  • Watch rebuilds reuse the first output. Restart the build after you change the spec or kubb.config.ts.

Import a spec as a module

Import a config's input file, or any *.openapi.yaml or *.openapi.yml file, to get the output of every plugin in your config as one module. Kubb writes no files for it, and it works in the Vite dev server too.

src/pets.ts
import { type Pet, petStatusEnum } from './petStore.openapi.yaml'
  • The import uses the config whose input is that spec, or else the first config without an input. A config without input only serves imports.
  • Code a plugin writes to a separate file, such as a bundled client runtime, is not part of the module.
  • The input file loads whatever its name, so ./my-api.openapi.json works when it is a config's input. openapi-import gives no types for a .json import, because TypeScript does not let a content mapper register a .json extension.

For types in tsc and your editor, add openapi-import.