Exercise 2: PurgeCSS's Generate-Then-Remove vs. JIT's Generate-Only-What's-Found — Possible Solution ==================================================================== WHAT build-tooling1-8 ESTABLISHED ABOUT TREE SHAKING ------------------------------ Per build-tooling1-8, tree shaking is described as "ESM's own static-analysis payoff" — a JavaScript bundler statically analyzes which exported code is actually imported and used, and eliminates everything else from the final bundle, based on that analysis of the real source code. HOW THE OLDER PURGECSS-BASED APPROACH WORKED ------------------------------ Per this chapter, "rather than generating everything a framework could produce and eliminating unused output afterward — closer to how PurgeCSS, Tailwind's own older, pre-JIT approach, actually worked." PurgeCSS's own model was a two-step process: FIRST, generate the complete, full CSS output (the entire theoretically possible set of utility classes, or at minimum a large default set), and THEN, as a SEPARATE later pass, scan the project's own source files and remove whichever generated CSS rules turn out not to be actually used. The full set exists, however briefly, before being pruned down afterward. HOW MODERN JIT WORKS DIFFERENTLY ------------------------------ Per this chapter, "modern Tailwind's JIT engine flips this around and generates only what content-scanning found being used, from the start, rather than generating-then-pruning." JIT doesn't generate a large or complete set of CSS first — it scans the source files FIRST, and only ever generates CSS for the specific class names that scan actually discovered. There is no intermediate "everything" stage to prune down at all; only the exact classes found in the source are ever produced. THE REAL, SPECIFIC DIFFERENCE, TIED TO TREE SHAKING ------------------------------ The distinction mirrors a genuine, meaningful difference within the broader "eliminate unused output" idea tree shaking represents: PurgeCSS's own approach is closer to producing everything and then REMOVING what's unused (a subtractive process, working from a complete starting set), while modern JIT's approach is closer to producing ONLY what's needed from the very beginning (a purely additive, build-as-discovered process, never producing the unused portion in the first place). Both approaches achieve a similar END RESULT (a final stylesheet containing only used classes), but they get there through genuinely different mechanisms — subtract-from-everything vs. generate-only-what's-found — a distinction worth being precise about rather than treating "Tailwind does tree shaking" as a single, undifferentiated fact. WHY THIS WORKS AS AN ANSWER ------------------------------ It states both mechanisms precisely using the chapter's own wording, and explicitly connects the distinction back to build-tooling1-8's own tree-shaking framing, showing PurgeCSS as the subtractive variant and JIT as the purely additive variant of the same broader "eliminate unused output" principle.