Color scheme

Build Tooling

In the CSS Architecture reading you learned about a project structure where main.css imports a dozen smaller files using @import with @layer. That architecture is clean, organized, and easy to maintain during development. But it comes with a cost in production: every @import is a separate network request. This reading explains why that matters, introduces two tools that solve the problem in different ways, and prepares you to choose one for your own portfolio.

This is a conceptual reading, not a setup tutorial. You will learn what each tool does and why developers reach for it. The hands-on installation and configuration are covered in the Choose Topics for this unit: PostCSS Setup and Plugins and Lightning CSS Setup. One of your teammates will walk you through their chosen tool in a teaching video, and you will pick one for the Architecture and Build assignment.

The Problem: Too Many Requests

When the browser encounters an @import inside a CSS file, it has to stop, fetch the imported file, parse it, and then continue. If that imported file contains more @import statements, the process repeats. Each round trip adds latency, especially on slower connections or mobile networks. A main.css with ten imports means the browser makes eleven requests (one for main.css itself, then one for each import) before it can render the page.

Compare that to a single bundled file. One request, one parse, done. The browser gets everything it needs in a single download. On a fast connection the difference might be a few milliseconds. On a real-world mobile connection it can be hundreds of milliseconds or more, and that delay blocks rendering because CSS is render-blocking by default.

Beyond request count, bundling opens the door to other optimizations. A bundler can minify your CSS by stripping whitespace, shortening color values, and removing redundant rules. It can add vendor prefixes automatically so you do not have to think about browser compatibility. And it can downlevel modern syntax for older browsers while letting you write cutting-edge CSS in your source files.

What a CSS Build Tool Does

At its core, a CSS build tool reads your source stylesheets, does some combination of useful work, and writes out one or more production-ready files. The "useful work" varies by tool, but the most common tasks are:

  • Bundling: resolving @import statements and inlining every imported file into one output file, eliminating extra network requests.
  • Minification: removing whitespace, comments, and unnecessary characters to reduce file size without changing behavior.
  • Vendor prefixing: automatically adding -webkit-, -moz-, or other prefixes for properties that still need them in your target browsers.
  • Syntax lowering: converting modern CSS features (like nesting or oklch() colors) into equivalent older syntax for browsers that do not support them yet.

Not every tool does all of these. Some are focused and do one thing well. Others are all-in-one solutions. The two tools this course highlights represent those two approaches.

PostCSS

PostCSS is a CSS processing framework built on a plugin architecture. By itself, PostCSS does almost nothing. It parses your CSS into an abstract syntax tree, hands that tree to whatever plugins you have configured, and writes the result back out. The power comes entirely from the plugins you choose.

This makes PostCSS extremely flexible. You install only the features you need, and nothing else runs. A minimal PostCSS setup for this course might use just two plugins:

  • postcss-import: resolves @import statements and inlines the imported files, producing a single bundled stylesheet.
  • autoprefixer: reads your browser targets and automatically adds (or removes) vendor prefixes wherever they are needed.

You could add more plugins as your needs grow. cssnano handles aggressive minification. postcss-preset-env lets you use future CSS syntax and compiles it to compatible output based on your browser targets. Each plugin is a separate npm package that you install and register in a configuration file.

The mental model for PostCSS is a pipeline. Your CSS enters one end, flows through each plugin in order, and comes out the other end transformed. You control what goes into the pipeline and in what order. If you want to explore how PostCSS Preset Env transforms modern CSS, try the PostCSS Preset Env Playground in your browser.

PostCSS Is Not a Preprocessor

PostCSS is sometimes compared to Sass or Less, but the comparison is misleading. Sass is a language with its own syntax. PostCSS is a framework that processes standard CSS (or close to it) through plugins. You write real CSS and PostCSS transforms it. You do not learn a new language.

Lightning CSS

Lightning CSS takes the opposite approach. Instead of a plugin pipeline, it is a single, self-contained tool written in Rust that handles bundling, minification, vendor prefixing, and syntax lowering all in one pass. You give it your entry-point stylesheet and a set of browser targets, and it does everything at once.

The performance difference is significant. Lightning CSS can process millions of lines of CSS per second because it runs as compiled native code rather than JavaScript. For most projects the speed difference is not the deciding factor, but on large codebases or in CI/CD pipelines where builds run frequently, it adds up.

The mental model for Lightning CSS is a compiler. You hand it a source file, tell it what browsers you support, and it gives you back a production-ready file with everything resolved, prefixed, and minified. There is no configuration file listing plugins. There is no plugin ecosystem to navigate. You get one tool that does the common tasks out of the box.

Lightning CSS understands modern CSS natively. It parses @layer, nesting, oklch() colors, and other recent features because its parser is built for the current CSS specification. When it lowers syntax for older browsers, it does so with full knowledge of what each feature means, not through pattern-matching heuristics. You can try it right now in the Lightning CSS Playground.

Comparing the Two

Both tools solve the same core problem (too many requests, no prefixing, no minification), but they make different tradeoffs:

  • PostCSS gives you full control. You choose exactly which plugins run and in what order. If you need a niche transform that only a community plugin provides, PostCSS can do it. The cost is more configuration and more dependencies to manage.
  • Lightning CSS gives you speed and simplicity. One tool, one command, no plugin configuration. The cost is less flexibility. If you need something Lightning CSS does not support natively, you either wait for it to be added or reach for PostCSS.

For this course, either tool works. Your portfolio's CSS is not large enough for performance to matter, so the real question is which workflow makes more sense to you. If you like explicit control and want to understand each piece of the pipeline, PostCSS is a good fit. If you prefer fewer moving parts and want to get from source to output with minimal setup, Lightning CSS is the better choice.

Why This Course Site Does Not Use a Bundler

You might be wondering: if bundling is so important, why does this course site ship unbundled CSS? Open DevTools and you will see individual @import requests, not a single minified file. This is a deliberate tradeoff.

This course site is maintained by a range of faculty and support staff, not all of whom are comfortable with build tooling. Keeping the CSS and JavaScript as plain, unbundled source files means anyone can open the repository, edit a file, and deploy without running an additional build step. There is no npm run build to remember, no Node version to match, and no compiled output to keep in sync with the source.

The tradeoff is slightly less optimized delivery. The CSS loads across multiple requests instead of one, and the JavaScript ships as ES modules rather than a single minified bundle. But the total payload is lightweight by design. The combined CSS and JS for this site are small enough that the performance cost of unbundled delivery is minimal, and the maintenance benefit of a zero-build workflow is significant for a team with mixed technical backgrounds.

This is a real architectural decision, not a shortcut. Every project weighs performance against maintainability, and different teams land in different places. In the Architecture and Build assignment you will run a bundler once so you know how the tooling works. After that week you may stop and keep shipping css/main.css, or you may keep the bundler. See After This Assignment: Stop or Keep. Understanding that bundling is a choice, not a requirement, is just as important as knowing how to set it up.

As we have said before, this course makes some choices that are not universally accepted. This is one of them. Bundling is usually the right choice for production sites, especially for larger projects and higher-traffic sites.

Choosing Your Tool

In the Architecture and Build assignment you will pick either PostCSS or Lightning CSS and integrate it into your portfolio. If your teammates have already posted their Choose Topic teaching videos for PostCSS Setup and Plugins or Lightning CSS Setup, watch both before deciding. If not, choose based on your own study and the tradeoffs covered here. Either way, pick the tool whose workflow makes the most sense to you.

Whichever tool you choose, the underlying architecture stays the same. Your main.css entry point, your layer declaration, your folder structure, and your token-first workflow are all unchanged. The build tool sits on top of that architecture and optimizes the output. It does not change how you write or organize your CSS.