Skip to content

Nuxt

unplugin-kubb/nuxt runs Kubb as a Nuxt module. It works with Nuxt 3 and Nuxt 4 and registers Kubb as both a Vite and webpack plugin depending on your Nuxt renderer.

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

Pass your Kubb config as the second element in the module tuple. defineNuxtConfig is auto-imported by Nuxt and does not need an explicit import.

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

Because the Nuxt module delegates to the Vite plugin under the hood, generation only runs during nuxt build. It does not run during nuxt dev. Run kubb generate before starting the dev server.