Configs2026年7月17日·1 分钟阅读

LightningCSS — Ultra-Fast CSS Parser, Transformer, and Minifier

An extremely fast CSS parser, transformer, bundler, and minifier written in Rust, with built-in support for CSS Modules, nesting, and vendor prefixing.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
LightningCSS Overview
直接安装命令
npx -y tokrepo@latest install 29c758c9-81dd-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

Introduction

LightningCSS (formerly Parcel CSS) is a CSS parser, transformer, bundler, and minifier written in Rust. It is designed to be orders of magnitude faster than JavaScript-based CSS tools while providing modern features like automatic vendor prefixing, syntax lowering, and CSS Modules support out of the box.

What LightningCSS Does

  • Parses CSS into a typed AST with full spec compliance and error recovery
  • Minifies CSS with advanced optimizations including shorthand merging and color conversion
  • Automatically adds or removes vendor prefixes based on browser targets
  • Lowers modern CSS syntax (nesting, color functions, custom media queries) for older browsers
  • Supports CSS Modules with scoped class names and composition

Architecture Overview

LightningCSS is built as a Rust library with bindings for Node.js (via NAPI-RS) and a standalone CLI. The parser produces a strongly-typed AST that preserves source maps. Transformations operate on this AST in a single pass where possible, applying browser target lowering, vendor prefixing, and minification together. The minifier performs structural optimizations like merging adjacent rules, collapsing shorthand properties, and converting color formats.

Self-Hosting & Configuration

  • Install the CLI via npm or download prebuilt binaries from GitHub releases
  • Use as a library in Node.js via the lightningcss npm package
  • Integrate with bundlers: native Parcel support, community plugins for Vite and Webpack
  • Configure browser targets using browserslist syntax for automatic prefix and lowering decisions
  • Enable CSS Modules, custom at-rules, or draft specs via API options

Key Features

  • 100x+ faster than cssnano and autoprefixer combined in benchmarks
  • Typed AST means transformations are safe and spec-correct
  • Built-in CSS Modules with composesFrom and scoped naming
  • Handles modern CSS features: nesting, :is(), color-mix(), light-dark(), and more
  • Preserves source maps through all transformations

Comparison with Similar Tools

  • PostCSS + Autoprefixer — plugin-based JS pipeline; LightningCSS is a single Rust binary, far faster
  • cssnano — JS minifier; LightningCSS minifies more aggressively and runs 100x faster
  • esbuild CSS — fast but less complete CSS handling; LightningCSS has deeper CSS spec support
  • Tailwind CSS compiler — utility-class generator; LightningCSS processes standard CSS files
  • sass/less — preprocessors with custom syntax; LightningCSS works with standard CSS and modern specs

FAQ

Q: Can LightningCSS replace PostCSS in my build pipeline? A: For most use cases (prefixing, nesting, minification), yes. If you rely on PostCSS plugins with custom transforms, you may still need PostCSS for those.

Q: Does it support Sass or Less syntax? A: No. LightningCSS processes standard CSS. You would run Sass/Less compilation first, then LightningCSS.

Q: How do I use it with Vite? A: Vite has experimental built-in support for LightningCSS as its CSS transformer via the css.transformer option.

Q: Is the AST API stable for building custom tools? A: The Rust API is well-documented and versioned. The Node.js API mirrors the Rust API with JavaScript-friendly types.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产