Beta You're reading the docs for Kubb v5, which is currently in beta. View the stable v4 docs
Skip to content

Barrel files

Barrel files are index.ts files that re-export everything from a directory, so consumers of the generated code write cleaner imports. Kubb generates them through @kubb/plugin-barrel.

Quick start

@kubb/plugin-barrel is included by default when you import defineConfig from the kubb package. To change how barrels are generated, add it to your plugins array:

kubb.config.ts
typescript
import {  } from 'kubb'
import {  } from '@kubb/plugin-barrel'

export default ({
  : { : './petStore.yaml' },
  : { : './src/gen', : { : 'named' } },
  : [()],
})

How it works

@kubb/plugin-barrel uses enforce: 'post', so it runs after all regular plugins finish. It walks the output tree and creates an index.ts in each directory, then a root index.ts at the top of output.path that re-exports from every plugin directory.

Exports

Export Purpose
pluginBarrel Plugin factory that emits barrel files based on output.barrel.
pluginBarrelName Stable string identifier ('plugin-barrel').

NOTE

Valid barrel.type values are 'all' and 'named'. At the plugin level, set barrel: { type: 'named', nested: true } for hierarchical barrels, or barrel: false to opt out for that plugin.