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>.
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.
| Tool | Import | Config file |
|---|---|---|
| Vite | kubb/vite | vite.config.ts |
| webpack | kubb/webpack | webpack.config.ts |
| Rspack | kubb/rspack | rspack.config.ts |
| Rollup | kubb/rollup | rollup.config.ts |
| Rolldown | kubb/rolldown | rolldown.config.ts |
| esbuild | kubb/esbuild | build.ts |
| Farm | kubb/farm | farm.config.ts |
| Nuxt | kubb/nuxt | nuxt.config.ts |
| Astro | kubb/astro | astro.config.mjs |
How the build runs Kubb
- The plugin applies the same defaults as
defineConfigand runsoutput.format,output.lint, andoutput.postGenerate. - It prints the run summary, not the
json,file, orhtmlreports. Usekubb generatefor 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
inputis that spec, or else the first config without aninput. A config withoutinputonly serves imports. - Code a plugin writes to a separate file, such as a bundled client runtime, is not part of the module.
- The
inputfile loads whatever its name, so./my-api.openapi.jsonworks when it is a config'sinput. openapi-import gives no types for a.jsonimport, because TypeScript does not let a content mapper register a.jsonextension.
For types in tsc and your editor, add openapi-import.
