plugins: [pluginBarrel()]TypeScript barrel file generator
@kubb/plugin-barrel
Generates index.ts barrel files for every plugin output, plus a root barrel when output.barrel is set on defineConfig.
- Downloads377.8K/ monthnpm, last 30 days
- GitHub stars1.8Kkubb-labs/kubb
- Unpacked size169.6kBv5.20.2 on npm
- Latest release2h agov5.20.2 · Nov 15, 2026
The Barrel plugin writes index.ts files that re-export the generated code, so you import everything from one entry point.
It writes a barrel in every folder of each plugin output that has a barrel setting, plus a root barrel when you set output.barrel on defineConfig.
Installation
kubb add plugin-barrelbun add -d @kubb/plugin-barrelpnpm add -D @kubb/plugin-barrelnpm install --save-dev @kubb/plugin-barrelyarn add -D @kubb/plugin-barrelkubb add installs the version the Kubb registry pins and adds pluginBarrel() to kubb.config.ts. It needs a kubb.config.ts, so run kubb init first in a new project.
Setup
No setup is needed. defineConfig adds pluginBarrel() to plugins when it is missing. Generator plugins such as pluginTs() turn on their own barrels in their default output, and a plugin without its own output.barrel inherits the root setting.
Options worth knowing
pluginBarrel() takes no arguments. Configure it with output.barrel, on defineConfig or on one plugin.
| Setting | Default | What it does |
|---|---|---|
type | Required | 'named' re-exports each symbol by name, which suits tree-shaking. 'all' writes export *. |
nested | false | Plugin only. Each barrel re-exports only its own folder and the barrels below it. |
namespace | false | Plugin only. Turns on nested barrels and adds a named namespace per subfolder, such as PetService. |
false | On a plugin, writes no barrel and leaves the plugin's files out of the root barrel. |
output to a plugin replaces its default barrel: { type: 'named' }, so the plugin falls back to the root setting.See Barrel rules.
Example
This config writes a root src/gen/index.ts that re-exports the generated types by name.
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()],
})export type { Category } from './types/Category'
export { petStatusEnum } from './types/Pet'
export type { Pet, PetStatusEnumKey } from './types/Pet'Dependencies
No extension dependencies.
