Bundlers & the build pipeline
How Vite/webpack resolve, transform, and split code; source maps; env handling; analyzing a bundle. Debugging a build is a rite of passage — be past it.
The mental model
A bundler is the machine that turns **the code you like to write** into **the code browsers can actually load fast.** You write hundreds of small ES modules, import TypeScript and JSX and CSS as if the browser understood them, and reference an image with import logo from './logo.png'. The browser understands none of that efficiently. The bundler is the translator and the optimiser in between.
The analogy: a book publisher. You (the author) write chapters in whatever order and format is convenient. The publisher resolves every cross-reference ("see chapter 4"), typesets everything into one consistent format, removes the notes-to-self you never meant to print (dead code), splits a 900-page manuscript into volumes people can actually carry (chunks), and prints a version with tiny margins for cheap shipping (minification) alongside a proofreader's copy with wide margins and line numbers (source maps). Same content, radically different artefact depending on who it is for.
**Why this exists — what breaks without it.** Browsers can load native ES modules directly, so in theory you need no bundler. In practice, a real app is a deep graph — thousands of modules, many from node_modules. Loading that graph over HTTP as individual files is a request waterfall: each module must download before the browser discovers its imports. There is no tree shaking, no minification, and no way to ship TypeScript, JSX, or import './styles.css'. The bundler exists to collapse that graph into a handful of optimised files, run every transform your source needs, and remove everything the user will not use — turning "correct but unusably slow" into "fast."
The distinction that clarifies the modern tooling landscape: dev and prod want opposite things. In development you want the server to start instantly and updates to appear the moment you save, even at the cost of shipping unbundled modules. In production you want the smallest, most-optimised bundle, even if the build takes a minute. Vite's whole design is that split — native ESM in dev, a Rollup bundle in prod — and understanding it explains most of what you will hit day to day.
- Deep dive
- Internal architecture
- Real-world use cases
- Best practices
- Common mistakes
- Performance
- Security
- Production troubleshooting
- Advantages & disadvantages
- Alternatives
- Interview expectations
- Interview questions
- Facts to remember
- Cheat sheet
- Quick revision