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
type Options = {
config: UserConfig
}
INFO
Type: Options
typescript
import { defineConfig } from '@kubb/core'
import { definePlugin as createSwagger } from '@kubb/swagger'
import { definePlugin as createSwaggerTanstackQuery } from '@kubb/swagger-tanstack-query'
import { definePlugin as createSwaggerTS } from '@kubb/swagger-ts'
/** @type {import('@kubb/core').UserConfig} */
export const config = {
root: '.',
input: {
path: './petStore.yaml',
},
output: {
path: './src/gen',
clean: true,
},
plugins: [
createSwagger({ output: false }),
createSwaggerTS({
output: {
path: 'models',
},
}),
],
}
typescript
import react from '@vitejs/plugin-react'
import kubb from 'unplugin-kubb/vite'
import { defineConfig } from 'vite'
import { config } from './kubb.config'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
react(),
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()],
})