You add a tidy folder: ten components, one index.ts that re-exports them all, and a single import line in the app:
import { Button } from "@/components/ui" ;
Enter fullscreen mode
Exit fullscreen mode
You only wanted Button . The dev build still feels heavier than it should.
The mental model: the whole shelf
A barrel file is an index.ts that re-exports a folder so you can import from one path. It's convenient. It's also like asking the library for one book and having the librarian pull every book on that shelf into the room before they hand you the right one.
The bundler's job is to follow every export * from and export { X } from while it figures out what your entry file actually needs. Tree shaking can still drop unused code from the final bundle.β¦