Beta You're reading the docs for Kubb v5, which is currently in beta. View the stable v4 docs
Skip to content

Nuxt

unplugin-kubb/nuxt runs Kubb as a Nuxt module. It works with Nuxt 3 and Nuxt 4. The module registers Kubb as both a Vite plugin and a webpack plugin, so Nuxt picks the right one for its active builder.

Install

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

Configure

Pass your Kubb config as the second element of the module tuple. Nuxt auto-imports defineNuxtConfig, so you do not import it.

nuxt.config.ts
typescript
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 defineNuxtConfig({
  modules: [['unplugin-kubb/nuxt', { config }]],
})

NOTE

With the default Vite builder, generation runs during nuxt build only, not during nuxt dev. Run kubb generate before you start the dev server.