Skip to content

Integrations

Kubb runs from the CLI, and it also runs from the places you already work. A bundler integration generates during your build, and Kubb Studio generates from a browser tab while Kubb runs on your machine.

Bundlers

kubb's bundler entrypoints run code generation inside your build. You skip the separate kubb generate step. Pass the same config you write in kubb.config.ts, and Kubb runs it as part of your build instead. Each entrypoint is powered by unplugin-kubb under the hood, re-exported from kubb so you only install one package.

NOTE

output.postGenerate runs commands after generation. It works with the CLI only, not with unplugin. Use kubb generate when you need a post-generation command.

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

Install kubb as a dev dependency.

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

Pick your bundler

Each bundler has its own entrypoint.

Bundler Entrypoint Docs
Vite kubb/vite Vite
Rollup kubb/rollup Rollup
Rolldown kubb/rolldown Rolldown
webpack kubb/webpack webpack
Rspack kubb/rspack Rspack
esbuild kubb/esbuild esbuild
Farm kubb/farm Farm
Nuxt kubb/nuxt Nuxt
Astro kubb/astro Astro

Options

Pass your Kubb config to the config option. It takes a UserConfig object with the same shape as kubb.config.ts.

vite.config.ts
typescript
import kubb from 'kubb/vite'
import { defineConfig as defineViteConfig } from 'vite'
import { pluginTs } from '@kubb/plugin-ts'

const config = {
  root: '.',
  input: './petStore.yaml',
  output: { path: './src/gen', clean: true },
  plugins: [pluginTs({ output: { path: 'models' } })],
}

export default defineViteConfig({
  plugins: [kubb({ config })],
})

Kubb Studio

Kubb Studio is the other way in, and it works differently from the entrypoints above. Rather than generating during a build, you open a session with kubb studio and drive generation from a browser tab. Kubb still runs on your machine against the files on disk, so your spec is never uploaded.

Reach for it when you want to change plugin options and see the result straight away, and for a bundler entrypoint when generation should happen as part of your build.