Skip to content
Plugin
Barrel logo
plugins: [pluginBarrel()]
Officialv5.20.2kubb >=5.8.3node >=22.22

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.

kubb add plugin-barrel
barrelindexexportsoutput

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-barrel

kubb 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.

SettingDefaultWhat it does
typeRequired'named' re-exports each symbol by name, which suits tree-shaking. 'all' writes export *.
nestedfalsePlugin only. Each barrel re-exports only its own folder and the barrels below it.
namespacefalsePlugin only. Turns on nested barrels and adds a named namespace per subfolder, such as PetService.
falseOn a plugin, writes no barrel and leaves the plugin's files out of the root barrel.
Passing your own 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()],
})

Dependencies

No extension dependencies.