How Barrel Files (index.ts Re-Exports) Silently Bloat Bundles and Slow Dev Builds
Barrel files, which consolidate module re-exports into a single index.ts, are a common TypeScript pattern that carries hidden performance costs. Because resolving one import from a barrel forces tools to load and evaluate all re-exported modules transitively, tree shaking, build speed, and memory usage can all suffer. The maintainers of @reactuses/core discovered this firsthand when a single-hook import was generating a 552 kB client chunk, which fell to 64 kB after restructuring away from the barrel. Beyond bundle size, barrel files also slow down Next.js dev servers and TypeScript compiler runs as codebases grow, and can introduce circular-dependency errors. The root cause in every case is the same: a module import triggers a full graph traversal, not a targeted symbol lookup.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in