Registry / devops / lightningcss-cli

lightningcss-cli

JSON →
library1.32.0jsnpmunverified

Lightning CSS is an extremely fast CSS parser, transformer, and minifier written in Rust, available as a standalone CLI, library, or plugin. Version 1.32.0 targets Node >= 12. It offers browser-grade parsing (via Mozilla's cssparser), automatic vendor prefixing based on browser targets (including Browserslist integration), syntax lowering for modern CSS (nesting, logical properties, color level 4/5, etc.), and extensive minification optimizations. Unlike tools like PostCSS or esbuild, it operates as a single-pass Rust binary that parses CSS with full type information, enabling deeper optimizations and smaller output. The CLI can be installed globally via npm and is designed for use in build pipelines or direct file processing.

npm install lightningcss-cli
INSTALL
IMPORT
SIG · LIGHTNINGCSS-CLI
L
lightningcss-cli
devopsjavascriptv1.32.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

lightningcss
import lightningcss from 'lightningcss'
const lightningcss = require('lightningcss')
Since v1, package ships ESM-only. Use dynamic import or ESM syntax. This is the library entry, not CLI. CLI is installed separately as 'lightningcss-cli'.
transform
import { transform } from 'lightningcss'
import { transform } from 'lightningcss-cli'
transform is named export from 'lightningcss'. CLI does not expose programmatic API.
bundle
import { bundle } from 'lightningcss'
import bundle from 'lightningcss/bundle'
bundle is a named export available since v1.0. Do not use subpath imports.

Demonstrates CLI minification and programmatic transform with browser targets.

// CLI usage // npx lightningcss-cli --minify input.css -o output.css // Programmatic usage with library import { transform } from 'lightningcss'; let { code } = transform({ filename: 'style.css', code: Buffer.from('.foo { color: red }'), minify: true, targets: { // Browser targets, optional chrome: 90 << 16 } }); console.log(code.toString()); // Output: .foo{color:red}
Debug
Known issues
breakingESM only: lightningcss package is ESM-only since v1. CommonJS require() will fail.
fix
Use import syntax or dynamic import(). If you must use CommonJS, use await import('lightningcss').
affects: >=1.0
deprecatedThe CLI package 'lightningcss-cli' is a separate package from the library 'lightningcss'. Do not confuse them.
fix
Install 'lightningcss' for programmatic use, 'lightningcss-cli' for command line.
affects: >=1.0
gotchaTransform expects Code input as Buffer, not string.
fix
Pass code: Buffer.from(yourCSSString) or use fs.readFileSync.
affects: >=1.0
gotchaBrowser targets use internal version encoding: major << 16 | minor << 8 | patch. Example: Chrome 90 = 90 << 16 = 5898240.
fix
Use the provided helper or consult documentation for target encoding.
affects: >=1.0
deprecatedThe 'customAtRules' option was renamed to 'customAtRules'? Check changelog. (Note: placeholder as no specific deprecated feature found.)
fix
Refer to migration guide if upgrading from alpha versions.
affects: >=1.0
Errors
Common errors & fixes
ReferenceError: require is not defined
Using CommonJS require() on an ESM-only package.
fix
Switch to import syntax: import { transform } from 'lightningcss';
TypeError [ERR_INVALID_ARG_TYPE]: The "code" argument must be of type object. Received type string
Passing code as a string instead of a Buffer.
fix
Wrap CSS string in Buffer.from(): code: Buffer.from(cssString)
Error: Unknown at-rule or selector at position 10
Input contains CSS syntax not supported by Lightning CSS parser.
fix
Ensure CSS is valid or use vendor prefixes that Lightning CSS can lower. Check supported features.
Upgrade
Version history
1.32.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
6
Amazon
1
Resources
lightningcss-cli — npm install lightningcss-cli · libregistry