Skip to content

unplugin-kubb 🦙 ​

Kubb plugin for Vite, webpack, esbuild, Rollup, Nuxt, Astro and Rspack.

TIP

The hook option will not work with Unplugin. If you need to run Prettier or ESLint after the generation, use Kubb CLI instead.

Installation ​

shell
bun add unplugin-kubb @kubb/core
shell
pnpm add unplugin-kubb @kubb/core
shell
npm install unplugin-kubb @kubb/core
shell
yarn add unplugin-kubb @kubb/core

Options ​

config ​

Define the options for Kubb.

TYPE

typescript
import type { UserConfig } from "@kubb/core"

type Options = {
  config: UserConfig
}

INFO

Type: Options

typescript
import kubb from 'unplugin-kubb/vite'
import { defineConfig as defineViteConfig } from 'vite'
import { defineConfig, UserConfig } from '@kubb/core'
import { pluginOas } from '@kubb/plugin-oas'
import { pluginTanstackQuery } from '@kubb/swagger-tanstack-query'
import { pluginTs } from '@kubb/swagger-ts'

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

// https://vitejs.dev/config/
export default defineViteConfig({
  plugins: [
    kubb({
      config,
    }),
  ],
})

Examples ​

Vite ​

ts
// vite.config.ts
import kubb from 'unplugin-kubb/vite'

export default defineConfig({
  plugins: [
    kubb({/* options */}),
  ],
})

Rollup ​

ts
// rollup.config.js
import kubb from 'unplugin-kubb/rollup'

export default {
  plugins: [
    kubb({/* options */}),
  ],
}

webpack ​

ts
// webpack.config.js
module.exports = {
  /* ... */
  plugins: [
    require('unplugin-kubb/webpack')({/* options */}),
  ],
}

Nuxt ​

ts
// nuxt.config.js
export default defineNuxtConfig({
  modules: [
    ['unplugin-kubb/nuxt', {/* options */}],
  ],
})

This module works for both Nuxt 2 and Nuxt Vite

Vue CLI ​

ts
// vue.config.js
module.exports = {
  configureWebpack: {
    plugins: [
      require('unplugin-kubb/webpack')({/* options */}),
    ],
  },
}

esbuild ​

ts
// esbuild.config.js
import { build } from 'esbuild'
import kubb from 'unplugin-kubb/esbuild'

build({
  plugins: [kubb()],
})

Released under the MIT License.