How-to guides

Add barrel files support

Generate index.ts barrel files for every plugin output directory with @kubb/plugin-barrel, the post-enforced plugin built into Kubb.

A barrel file is an index.ts that re-exports everything from a directory. Consumers then import from one place instead of reaching into individual files, keeping imports short and stable. Kubb generates these files through @kubb/plugin-barrel.

@kubb/plugin-barrel ships inside kubb, and defineConfig registers it for you, but output.barrel defaults to false, so it generates nothing until you opt in.

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
src/gen/index.ts
export { Pet, User } from './models'
export { getPetById, getInventory } from './clients'