@kubb/plugin-barrel
Barrel-file plugin for Kubb
Automatically generates index.ts re-export files for each plugin output directory.
Installation
bun add @kubb/plugin-barrel
# or
pnpm add @kubb/plugin-barrel
# or
npm install @kubb/plugin-barrelUsage
Add pluginBarrel to the plugins array in your kubb.config.ts:
import { defineConfig } from 'kubb'
import { pluginBarrel } from '@kubb/plugin-barrel'
export default defineConfig({
input: {
path: './openapi.yaml',
},
output: {
path: './src/gen',
},
plugins: [
pluginBarrel({
type: 'named',
}),
],
})Options
| Option | Type | Default | Description |
|---|---|---|---|
type |
'all' | 'named' | 'propagate' |
'named' |
Export style for the generated barrel files |
Export types
| Value | Output |
|---|---|
'all' |
export * from './...' — wildcard re-exports |
'named' |
export { ... } from './...' — named re-exports, tree-shaking friendly |
'propagate' |
export * from './...' on index files only, propagating up through directories |
How it works
After every plugin finishes generating files, @kubb/plugin-barrel walks the output tree and creates an index.ts in each directory, re-exporting everything inside. It then creates a root index.ts at the top of the output path that re-exports from all plugin directories.
@kubb/plugin-barrel uses enforce: 'post' so it always runs after all regular plugins complete, giving it access to the full set of generated files.
Supporting Kubb
Kubb is an open source project, and its development is funded entirely by sponsors. If you would like to become a sponsor, please consider: