> Index of every page on this site: [llms.txt](https://kubb.dev/llms.txt)

# Barrel rules

Which barrel setting applies to each plugin, when a plugin gets no barrel, and what each `index.ts` re-exports.

## Which barrel setting applies

The Barrel plugin runs after every other plugin, so each barrel sees the final set of files. For each plugin, Kubb reads its `output.barrel` first, then the root [`output.barrel`](https://kubb.dev/docs/5.x/reference/configuration#outputbarrel), then `false`.

- The root `output.barrel` accepts only `type` and is always flat. It has no `nested` or `namespace` field.
- Passing your own `output` to a plugin replaces its default `barrel: { type: 'named' }`, so the plugin falls back to the root setting.

| Root `output.barrel` | Plugin `output.barrel`                                                                                 | Plugin barrels               | Root barrel                      |
| -------------------- | ------------------------------------------------------------------------------------------------------ | ---------------------------- | -------------------------------- |
| `false` (default)    | Plugin default `{ type: 'named' }`                                                                     | Yes                          | No                               |
| `false` (default)    | Unset, because your own `output` replaced the default, as in `pluginTs({ output: { path: 'types' } })` | No                           | No                               |
| `{ type }`           | Unset                                                                                                  | Yes, with the root `type`    | Yes                              |
| `{ type }`           | `{ type, … }`                                                                                          | Yes, with the plugin setting | Yes                              |
| `{ type }`           | `false`                                                                                                | No                           | Yes, without this plugin's files |

## When a plugin gets no barrel

| Case                                                            | Result                                                                                                                               |
| --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| `output.mode: 'file'`                                           | The root barrel re-exports the single file directly.                                                                                 |
| The plugin writes to the output root, with no own `output.path` | The root barrel picks up its files.                                                                                                  |
| `output.path` resolves outside the root `output.path`           | With a directory barrel, the build fails with `KUBB_PATH_TRAVERSAL`. With `barrel: false` or `mode: 'file'`, Kubb does not check it. |

## What goes into a barrel

- Every `.ts`, `.tsx`, `.js`, and `.jsx` file below the folder, sorted by name. Other `index.ts` files are not re-exported as leaves.
- The barrel file is always `index.ts`.
- With `type: 'named'`, a file without sources is re-exported whole.
- With `type: 'all'`, a file whose sources are all marked as not indexable is left out.
- With `nested`, a subfolder barrel is always chained with `export *`, also for `type: 'named'`, because the child barrel already lists the names.

A plugin's barrels get its `output.banner` and `output.footer` only when the plugin sets them. They never get the default "Generated by Kubb" notice, and the root barrel gets neither.

## Namespaces for tag groups

[`namespace`](https://kubb.dev/extensions/kubb-labs/plugin-barrel/options#namespace) exposes each immediate subfolder as a named namespace, next to its standalone exports. Combine it with tag [`group`](https://kubb.dev/docs/5.x/reference/plugin-options#group)s to export each group as a named service.

- A namespace takes the PascalCase folder name. A name that does not start with a letter gets an `_` prefix, and a name with no letters or digits becomes `_`.
- An enabled root barrel forwards the namespaces too.
- Editors can offer auto-imports for these namespaces when the generated files belong to the TypeScript project.

For tag-grouped fetch clients, name the service folders with `group.name`. Leave the fetch `sdk` option unset so React Query can import the standalone operation functions. For a `pet` tag, the operations land in `src/gen/client/petService/`. Both calling styles, `PetService.getPetById()` and `getPetById()`, work next to the generated hooks and query options.

## Sitemap

See the full [sitemap](https://kubb.dev/sitemap.md) for all pages.
