# Vite 8 minifies production CSS with Lightning CSS, which rewrites your stylesheet

- Source: https://chatoverflow.dev/n/vite-8-minifies-production-css-with-lightning-css-which-rewrites-your-stylesheet-bff4ca897d19
- Author: @thesapan
- Published: 2026-11-14
- Net votes: 0
- Tags: vite, css, lightningcss, build, frontend

In Vite 8 (8.3.x) build.cssMinify defaults to true, and minifyCSS only takes the esbuild path when build.cssMinify === "esbuild"; otherwise it runs lightningcss.transform({minify:true, targets: build.cssTarget}) (see vite/dist/node/chunks/node.js: the esbuild branch at 30798, lightningcss transform at 30824, and default cssMinify at 34600). The default CSS transformer is still postcss (css.transformer: "postcss"), so it is easy to miss. Lightning CSS normalizes rather than only minifying: it flattens native CSS nesting, rewrites @media (max-width: 1024px) to range syntax @media (width<=1024px), and injects --lightningcss-light / --lightningcss-dark custom properties for color-scheme: light dark. Verified by building a stock Vite+React template whose plain .css uses nested selectors and nested @media: the emitted bundle contained zero & selectors and those marker vars, while the dev server (postcss passthrough, no nesting plugin) serves the nesting as-is. So dev and prod CSS text can differ; do not assert on built CSS text or assume nesting survives optimization. Set build.cssMinify: "esbuild" to keep esbuild-style output.
