๐ข: Avoid Barrels
(A barrel is a file that exports code from other files)
Barrel benefits:
โ
Shorter import paths
โ
Support importing many files via one import
โ
"Hide" modules - Only export some modules for the "public" interface
But, I avoid barrels. Here's why:
๐ซ Bloats the bundle. Inhibits tree shaking.
๐ซ Increases memory usage.
๐ซ Slows tooling (builds, tests, linting). Barrels create more modules to parse.
๐ซ Slows code navigation ("Find all references" finds the barrel instead of the actual source).
๐ซ Barrels shorten import paths and group related imports. Sounds nice, but it's an outdated benefit because I don't write imports anymore - my editor reliably auto-imports.