Skip to content
Search

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:

import i18n from '@/i18n/config';
import {useTranslation} from 'react-i18next';

With a barrel:

import i18n, {useTranslation} from '@/i18n';

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

See also

author Zer0 sitemap