Why do we bundle JavaScript at all?
Historically: browsers had no module system, so bundlers gave us import/export and resolved node_modules. Under HTTP/1.1, fewer requests also mattered enormously.
Browsers now support ESM natively and HTTP/2 multiplexes, so "reduce request count" is much weaker. Bundlers stayed because of everything else they do:
- Dependency resolution — bare specifiers (
import x from 'lodash') still aren't resolvable by a browser without an import map. - Transformation — TypeScript, JSX, Sass, and syntax down-levelling for target browsers.
- Optimisation — tree shaking, minification, code splitting, asset hashing.
- Non-JS assets — importing CSS, images and SVGs as modules.
- Waterfalls — unbundled deep import chains mean the browser discovers modules level by level, which is slow on a real network.