Re-exports and Barrel Files
Create index files to simplify import paths.
Welcome
Barrel files (index.ts) aggregate and re-export module contents, creating a simple public API for a directory so consumers have cleaner import paths.
What Is a Barrel File
A barrel is an index.ts that re-exports everything from the same directory. Consumers import from the directory instead of individual files.
// src/models/index.ts (barrel)
export { User } from './user';
export { Product } from './product';
export { Order } from './order';All lessons in this course
- ES Module Syntax: import and export
- Re-exports and Barrel Files
- Type-Only Imports and Exports
- Namespaces vs Modules: Modern Usage