The Web FrontendDeeper

Kayavak / The Web Frontend / FE·30 Build Tooling & Monorepos / Deeper

Deeper · The Web Frontend

Build Tooling & Monorepos

The questions the chapter doesn't stop for: why this exists, the model to keep in your head, what changes when an assumption does, how sure we are of each claim, and what's still open. Read it after the chapter; back to the chapter.

Why does this exist?

For most of its life JavaScript had no module system: scripts shared one global scope and depended on load order. Node.js (2009) adopted CommonJS require, and npm (Isaac Schlueter, 2010) made publishing and installing packages trivial, which grew into the largest package registry in existence. Browsers couldn't load CommonJS, so bundlers appeared: Browserify (2011) and webpack (Tobias Koppers, 2012) followed every require and produced one file a browser could run. ES2015 finally standardised modules (import/export), static enough for tools to remove unused code (tree shaking).

Tools then got faster and simpler. esbuild (Evan Wallace, 2020), written in Go, bundled 10–100× faster than JavaScript-based tools; Vite (Evan You, 2020) served native modules in development and bundled only for production. The dependency explosion had a cost: in 2016 the removal of left-pad, an 11-line package, broke builds across the industry, and lockfiles, integrity hashes and stricter package managers (pnpm) followed.

The mental model

Try it yourself first: write your own model in the Mental Model Explorer, then compare.

Your code is a graph of modules. Tooling resolves that graph, checks it, transforms it and packs it into files a browser can load quickly, and makes the same result reproducible on every machine.

Question Answer
What is it? Package managers, module systems, compilers, bundlers, linters, formatters and monorepo tools
Problem it solves Turning many source files and dependencies into fast, correct, reproducible deployable assets
Parts Registry and package manager, lockfile, module resolution, transpile, bundle and minify, code-quality checks, task caching
How it works Resolve versions into a tree, pin it, follow imports into a graph, transform each module, split and emit chunks
Assumptions The same lockfile and tool versions give the same output
When they change Unpinned ranges or a changed registry package produce different builds on different days
Where it fails Dependency sprawl: every package is code you run and trust (ch28)
Related ideas Compilers and linkers (Foundations, ch10); reproducible builds (DevOps)

What if?

What if there were no lockfile?

Reason it through, then open

Every install would resolve ^1.2.0 to whatever is newest today. Two developers, or CI and production, could run different code from the same commit, and a bad patch release of a deep dependency would reach you without any change on your side. The lockfile pins exact versions and integrity hashes, so the dependency tree is part of the commit.

What if bundles weren't split?

Reason it through, then open

Every page would download all the code for every page: the admin screens for every visitor, the chart library on the login page. And any change anywhere would invalidate the one cached file. Splitting by route and keeping vendor code in separately hashed chunks means users fetch only what a page needs and re-fetch only what changed.

Where the boundary is

Aspect ES modules CommonJS
Syntax import / export require() / module.exports
Resolved Statically, before running Dynamically, while running
Tree shaking Yes Hard: any require could be computed
Loading Asynchronous Synchronous
Where Browsers, modern Node, Deno, Bun Older Node code

How sure are we?

Claim How it's known Where from
left-pad's removal broke many builds in March 2016 Historical npm's own post-mortem
esbuild is 10–100× faster than JavaScript bundlers Measured Its published benchmarks, on its test projects
Lockfiles make installs reproducible Model For the dependency versions; scripts run at install time can still vary
Static imports allow tree shaking Theorem, with care Side-effectful modules must be kept; tools rely on sideEffects hints

Still open

JavaScript tooling is being rewritten in faster languages (Rust and Go: Rolldown, Oxc, Biome, Turbopack), and the CommonJS-to-ESM transition in Node is still not complete. How to make install scripts and transitive dependencies safe is an open supply-chain problem.

What would change your mind? If browsers loaded thousands of small modules as fast as one bundle, bundling would become optional. HTTP/2 narrowed the gap, but deep import chains still cost round trips.

Recall

Why does a lockfile matter?

It pins exact dependency versions and hashes, so every install from a commit is the same.

Why are ES modules tree-shakeable and CommonJS mostly not?

ES imports are static and known before running; require can be dynamic.

What did the left-pad incident show?

How much of the ecosystem depends on tiny transitive packages, and how fragile builds were without pinning.

Why split bundles by route?

Users download only what a page needs, and caches survive changes to unrelated code.

Reflect

Be honest with yourself; this stays in your browser. Anything you can't tick yet is what to revisit.