talira

Lightning CSS

An extremely fast CSS parser, transformer, bundler, and minifier

open sourceMPL-2.0self-hostablefree

Lightning CSS is a CSS parser, transformer, bundler and minifier written in Rust on the cssparser and selectors crates from Mozilla's Firefox, which its makers say is over 100 times faster than comparable JavaScript tools. It compiles modern CSS (nesting, custom media queries, high-gamut colours, logical properties, new selectors) to syntax your browser targets understand, adds and removes vendor prefixes, supports CSS modules with scoped names, inlines @import rules, and minifies by merging rules, shortening colours and reducing calc(). You use it as a JavaScript or Rust library, a standalone CLI or a WebAssembly build, and it is the default CSS transformer in Parcel and an option in Vite and webpack's CSS minimizer. It is MPL-2.0-licensed and made by the Parcel project.

Problems it solves

  • our CSS build with PostCSS plugins is slow on a big stylesheet
  • use CSS nesting and modern colour functions now and have them compiled for older browsers
  • add vendor prefixes for our browser targets without maintaining a PostCSS plugin chain
  • minify CSS smaller than our current minifier does
  • scope class names per file with CSS modules and get the mapping in JavaScript
  • inline @import rules into one stylesheet at build time
  • parse and transform CSS from Rust with a parser that understands every property like a browser
  • replace autoprefixer and postcss-preset-env with a single fast tool
  • minify CSS in the browser or Deno with a WebAssembly build

Features

  • parses every CSS rule, property and value as a browser would, on Mozilla's cssparser and selectors crates
  • syntax lowering for nesting, custom media queries, high-gamut colours, logical properties and new selectors by browser targets
  • automatic vendor prefixing and removal of unneeded prefixes
  • minifier that merges shorthands and rules, removes default values, reduces calc() and shortens colours
  • CSS modules with locally scoped classes, ids, keyframes and variables
  • bundle API that inlines @import rules
  • source maps
  • JavaScript (Node) and Rust libraries, a standalone CLI and a WebAssembly build
  • visitor API for custom transforms
  • default CSS transformer in Parcel; built-in option in Vite and css-minimizer-webpack-plugin

Limitations

  • Doesn't replace every PostCSS plugin: custom plugins may still need PostCSS alongside it1

Capabilities

Has a command line toolplan not known

Alternatives

The same job

These do what Lightning CSS does.

  1. PostCSS A tool for transforming CSS with JavaScript
  2. esbuild An extremely fast bundler for the web
  3. Sass CSS with superpowers

Compare Lightning CSS with the top 3