Skip to content

Astro

unplugin-kubb/astro runs Kubb as an Astro integration. It hooks into Astro's Vite layer and runs generation during builds.

Install

shell
bun add -d unplugin-kubb
shell
pnpm add -D unplugin-kubb
shell
npm install --save-dev unplugin-kubb
shell
yarn add -D unplugin-kubb

Configure

astro.config.mjs
typescript
import { defineConfig as defineAstroConfig } from 'astro/config'
import kubb from 'unplugin-kubb/astro'
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 defineAstroConfig({
  integrations: [kubb({ config })],
})

NOTE

The Astro integration uses Vite under the hood with apply: 'build', so generation runs during astro build only. Run kubb generate before starting the dev server.