Lightning CSS (v1.32.0) is an extremely fast CSS parser, transformer, and minifier written in Rust, distributed as a WebAssembly module for Node.js and the browser. It provides typed property values, browser-grade parsing via Mozilla's cssparser and selectors, automatic vendor prefixing based on browser targets (including browserslist support), syntax lowering for modern CSS (nesting, logical properties, color functions, selectors, math functions), and advanced minification (shorthand merging, gradient minification, calc reduction). It is a standalone library used by Parcel and can be integrated with any build tool. It ships TypeScript types and supports both ESM and CommonJS. Compared to alternatives like cssnano or postcss, it offers significantly faster performance and more comprehensive value-level optimizations.
npm install lightningcss-wasmNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Minifies a CSS string with Lightning CSS, converting rgba to hex shorthand, shortening transition duration, and removing vendor prefixes not needed for target browsers.
Encode your CSS string to a Uint8Array using `new TextEncoder().encode(code)` before passing.
Use `cssModules: true` instead of `css_modules: true`.
In browsers, use a bundler that supports WASM (e.g., webpack with asyncWasm) or load via `@parcel/wasm` helper.
Use the `bundle` function with `resolver` for custom at-rules, or use the `visitor` option in `transform`.
Encode the string: `new TextEncoder().encode(cssString)`
Add `customAtRules: { customSelector: { prelude: '<custom-selector>', body: '<declaration-list>' } }` to the transform options.Use `import { transform } from 'lightningcss-wasm'` instead of `require('lightningcss-wasm')`.Run `npm install lightningcss-wasm` and ensure your import is `from 'lightningcss-wasm'`.