skip to content

When would you replace a PostCSS pipeline of postcss-preset-env and cssnano with Lightning CSS, and what does the switch give up?

level: seniorimportance: nice to knowfreq 4%

answer

  1. one tool against many plugins
  2. native code, fewer packages
  3. targets in its own option
  4. no PostCSS plugins inside it
  5. inventory the plugin list first

basics

~20 s

Lightning CSS is a single Rust-based transformer that lowers modern syntax for browser targets, prefixes and minifies in one fast tool. Switch when the pipeline is only standard lowering and minifying; stay on PostCSS while you depend on PostCSS plugins.

solid answer

~50 s

Lightning CSS is one native, Rust-based tool that parses CSS, lowers modern syntax such as nesting and media query ranges for a set of browser `targets`, adds the prefixes they need and minifies. A PostCSS pipeline does the same work with separate plugins (postcss-preset-env with Autoprefixer, then cssnano) chosen and ordered in a config. Switching buys speed and fewer packages, and some builds already use it: Vite minifies CSS with Lightning CSS by default while PostCSS still does the other processing. What you give up is the PostCSS plugin ecosystem. PostCSS plugins do not run inside Lightning CSS, so an in-house rewrite, Sass-style nesting with postcss-nested or `url()` rewriting must be dropped, ported to its own visitor API, or left in a PostCSS step. Its draft-feature support sits behind its own options. Decide by listing every plugin and asking what replaces each one.

go deeper

for a junior

Recall that Lightning CSS is one fast tool that lowers, prefixes and minifies CSS, while PostCSS does the same jobs through separate plugins.

for a middle

Explain which plugins in a PostCSS config Lightning CSS could replace, and which ones it cannot because PostCSS plugins do not run inside it.

for a senior

Make the switch decision from an inventory: standard plugins move, custom ones are ported, kept in a PostCSS step or deleted, and one target list feeds every tool.

for a principal

Weigh build speed and fewer dependencies against extensibility and team knowledge of the PostCSS API, and decide which build step each tool should own long term.

## Two architectures A **PostCSS pipeline** is a host plus plugins: a parser, a list of independent plugins you choose and order, and a stringifier. **Lightning CSS** is a single transformer, written in Rust, that does in one tool what a typical pipeline spreads over several packages. Both can produce the same kind of output: CSS lowered and prefixed for a set of browsers, then minified. | | PostCSS pipeline | Lightning CSS | |---|---|---| | Shape | host + ordered plugins | one transformer | | Lowering for older browsers | postcss-preset-env, by stage, features and Browserslist | built in, driven by a `targets` option | | Prefixing | Autoprefixer (inside postcss-preset-env) | built in | | Minifying | cssnano, with presets | built in | | Draft features | preset stage or features | its own `drafts` options | | Custom transforms | any PostCSS plugin, or your own | its own visitor API; PostCSS plugins do not run | | Engine | JavaScript plugins | native code | ## Where Lightning CSS already shows up - **Vite** uses Lightning CSS to **minify CSS in production builds by default**, while PostCSS still does the rest of the CSS processing, and it offers running Lightning CSS for all CSS processing as an experimental option. The option names belong to the Vite configuration material. - **Tailwind CSS v4** runs it internally to lower nesting and minify. So the honest question is often not "PostCSS or Lightning CSS" but **which step each tool owns**. ## What the switch buys - **Build time.** One native tool instead of a chain of JavaScript plugins, which matters most on large stylesheets and in watch mode. - **Fewer moving parts.** No plugin order to get wrong, no duplicate Autoprefixer, and fewer packages to update. - **One place for syntax lowering.** Nesting, media query ranges and prefixes are handled together for the same targets. ## What it gives up - **The PostCSS plugin ecosystem.** Lightning CSS does not load PostCSS plugins. The exhibition-guide site's in-house `--gutter-units` rewrite, postcss-nested's Sass-style nesting, postcss-url's `url()` rewriting, linting plugins and the CSS Modules plugins all stop working as they are (Lightning CSS has its own CSS Modules support, configured separately). - **Custom transforms come at a porting cost.** They can be rewritten against Lightning CSS's own visitor API, which is a different API from the PostCSS one your team knows. - **Fine-grained feature control.** postcss-preset-env exposes a stage floor, per-feature IDs, `preserve` and debug logs. Lightning CSS has its own include, exclude and draft options, and they are not a one-to-one match. - **Target wiring.** Its `targets` are an option of the tool. Make sure they come from the same Browserslist query the rest of the build uses, or the minifier and the transformer will serve different browsers. ## Deciding 1. **Inventory the plugin list.** Mark each plugin as standard lowering, prefixing, minifying or custom. 2. **If everything is standard**, Lightning CSS can replace the chain. Compare the output for your real targets, including the kiosk iPads, before and after the switch. 3. **If custom plugins remain**, either port them or keep a PostCSS step for them and let Lightning CSS handle lowering and minifying afterwards. 4. **Keep one target list** and check that each tool reads it. 5. **Measure the build.** If CSS is a small share of build time, the speed argument may not pay for a port. A senior answer names a fair trade: Lightning CSS is faster and simpler when the pipeline is standard; PostCSS remains the extensible host when the codebase depends on transforms nobody else ships. ## Applying it to the exhibition-guide site The site's pipeline is postcss-import, the in-house `--gutter-units` rewrite, postcss-preset-env and cssnano. Three of the four are standard work: inlining imports, lowering and prefixing, and minifying. The fourth is a custom transform. Three paths are reasonable: 1. **Keep PostCSS as it is.** The build is small and the plugin is still needed. 2. **Hybrid.** A PostCSS step runs only the rewrite, and Lightning CSS does lowering, prefixing and minifying afterwards for the same targets, including the kiosk iPads. 3. **Retire the plugin.** Rewrite the legacy declarations in the source once, then move everything that remains to Lightning CSS. The third path is usually the cleanest. A migration plugin is a temporary tool, and deleting it removes the only reason to keep a separate host.

  • Can a codebase use both PostCSS and Lightning CSS in one build?
    Yes, and it is common: PostCSS runs the custom or non-standard plugins, and Lightning CSS handles lowering and minifying afterwards, or only minifying. The risk is two target lists, one for each tool, so derive both from the same Browserslist query and compare the output for your oldest targets.
  • Your pipeline has one in-house PostCSS plugin. What are the options if you want Lightning CSS everywhere else?
    Keep a small PostCSS step that runs only that plugin before Lightning CSS. Or port its logic to Lightning CSS's own visitor API. Or, if it is a migration aid like a legacy declaration rewrite, fix the source files once and delete the plugin, so nothing custom remains.

  • Lightning CSS runs existing PostCSS plugins, so the config carries over unchanged.
  • Lightning CSS only minifies; it cannot lower modern syntax for older targets.
  • Switching is always right because native code is faster.
  • Custom transforms are impossible once you leave PostCSS.
  • Moving to Lightning CSS needs no change to how browser targets are set.