Challenge 2: Why node_modules Still Needs esbuild Pre-Bundling — Possible Solution ==================================================================== WHAT WOULD GO WRONG SERVING DEPENDENCIES RAW ------------------------------ Per this chapter's own explanation, two real problems would occur if node_modules packages were simply served unbundled the same way the project's own source code is: 1. Many npm packages are still published as CommonJS (per build-tooling1-2's own dual-build point), not ES Modules. Browsers cannot execute CommonJS's require()/module.exports natively at all — per build-tooling1-1's own explanation, this isn't a performance problem, it's a hard failure, since require() simply doesn't exist as a function in a browser environment. 2. Even packages that ARE published as ES Modules are often split across HUNDREDS of small internal files. Serving each of those files as its own separate native ESM request would mean hundreds of individual network round-trips just to load a single dependency — a real, measurable performance cost of its own, even though each individual file is small. WHY THIS DOESN'T CONTRADICT VITE'S "DON'T BUNDLE YOUR OWN SOURCE" IDEA ------------------------------ Per this chapter's own explanation, Vite's core insight applies specifically to the APPLICATION'S OWN source code — code the developer is actively writing and changing constantly, where fast re-fetching after every edit matters most. node_modules dependencies are fundamentally different: they don't change from one moment to the next during a normal development session, so pre-bundling them ONCE, then caching the result, doesn't cost anything on every subsequent file change the way bundling the developer's own actively-changing source would. Vite's actual strategy, per this chapter, is a genuine two-tier approach — leave frequently-changing source code unbundled, but do a one-time, cached bundling pass over comparatively stable dependencies, using esbuild specifically because (per Ch.6) it can do that one-time pass extremely fast. WHY THIS WORKS AS AN ANSWER ------------------------------ It names both concrete problems raw dependency serving would cause (CommonJS incompatibility, and excessive network requests for multi- file packages), and explains why pre-bundling dependencies once doesn't conflict with Vite's own "don't bundle your own source" philosophy, since dependencies and actively-edited source code have genuinely different change frequencies.