Integrations
unplugin-kubb runs code generation inside your build. You skip the separate kubb generate step. Pass it the same config you write in kubb.config.ts.
NOTE
hooks.done runs formatters and linters after generation. It works with the CLI only, not with unplugin. Use kubb generate when you need a post-generation callback.
IMPORTANT
Vite-based bundlers (Vite, Nuxt, Astro) generate during a build only. They skip generation on dev server startup. Run kubb generate before you start the dev server.
Installation
shell
bun add -d unplugin-kubb@betashell
pnpm add -D unplugin-kubb@betashell
npm install --save-dev unplugin-kubb@betashell
yarn add -D unplugin-kubb@betaPick your bundler
Each bundler has its own entrypoint.
| Bundler | Entrypoint | Docs |
|---|---|---|
| Vite | unplugin-kubb/vite | Vite |
| Rollup | unplugin-kubb/rollup | Rollup |
| Rolldown | unplugin-kubb/rolldown | Rolldown |
| webpack | unplugin-kubb/webpack | webpack |
| Rspack | unplugin-kubb/rspack | Rspack |
| esbuild | unplugin-kubb/esbuild | esbuild |
| Farm | unplugin-kubb/farm | Farm |
| Nuxt | unplugin-kubb/nuxt | Nuxt |
| Astro | unplugin-kubb/astro | Astro |
Options
Pass your Kubb config to the config option. It is a UserConfig object with the same shape as kubb.config.ts.
typescript
import kubb from 'unplugin-kubb/vite'
import { defineConfig as defineViteConfig } from 'vite'
import { defineConfig } from 'kubb'
import { pluginTs } from '@kubb/plugin-ts'
const config = defineConfig({
root: '.',
input: { path: './petStore.yaml' },
output: { path: './src/gen', clean: true },
plugins: [pluginTs({ output: { path: 'models' } })],
})
export default defineViteConfig({
plugins: [kubb({ config })],
})