Barrel File
lastmod 2026-03-07created 2026-03-072 edits
A barrel file (Barrel File) is an index.ts file that gathers the exports of several modules in one place and re-exports them.
Purpose
- Simplifies import paths
- Encapsulates the internal structure of a module
Example
Without a barrel:
With a barrel:
Caveats
- Tree-shaking impact:
export *can make it harder for bundlers to remove unused code. - Circular references: circular dependencies can occur if barrel files reference each other
- No JSDoc needed: files that only re-export do not need separate documentation