Add barrel files
A barrel file is an index.ts that re-exports everything in a directory, so consumers import from one place. @kubb/plugin-barrel ships inside kubb and defineConfig registers it for you. The root barrel is off by default, so Kubb writes no root index.ts until you set output.barrel. Each plugin's default output carries barrel: { type: 'named' }, so a plugin such as pluginTs() already writes types/index.ts.
Toggle the export style and barrel depth to see what each index.ts re-exports.
- src/gen/
- models/
- Pet.ts
- User.ts
- clients/
- pet/
- getPetById.ts
- store/
- getInventory.ts
- pet/
- models/
export { Pet, User } from './models'export { getPetById, getInventory } from './clients'
Enable the root barrel
Set output.barrel on defineConfig to write the root index.ts. A plugin inherits this value only when its own output sets no barrel. A plugin left on its default output keeps { type: 'named' }. type is 'named' for per-symbol re-exports or 'all' for export *. See type for the difference.
import { defineConfig } from 'kubb/config'
import { pluginTs } from '@kubb/plugin-ts'
export default defineConfig({
input: './petStore.yaml',
output: { path: './src/gen', barrel: { type: 'named' } },
plugins: [pluginTs()],
})Adjust a single plugin
Set barrel inside a plugin's output to change or drop that plugin's barrel. nested: true writes an index.ts in every subdirectory instead of one flat barrel. false skips the plugin's barrel and drops its files from the root barrel. A plugin gets a barrel only in output.mode: 'directory', the mode an output.path without a file extension implies.
import { defineConfig } from 'kubb/config'
import { pluginTs } from '@kubb/plugin-ts'
import { pluginZod } from '@kubb/plugin-zod'
export default defineConfig({
input: './petStore.yaml',
output: { path: './src/gen', barrel: { type: 'named' } },
plugins: [
pluginTs({ output: { path: 'types', barrel: { type: 'all', nested: true } } }),
pluginZod({ output: { path: 'zod', barrel: false } }),
],
})