lightningcss-cli
Advanced tools
Weekly downloads
Changelog
v1.19.0
This release includes several features and improvements for the custom visitor API, including support for defining how to parse custom at rules. In addition, lots of bug fixes are included for auto prefixing, selector downleveling, and more.
When Lightning CSS does not know how to parse an unknown at rule, it stores the prelude and body as a list of raw tokens. Without a definition for how a rule should be parsed, Lighting CSS doesn't know how to interpret it. Tokens are fine for simple use cases, but if you are building a custom visitor plugin that processes a custom at-rule, and want it to integrate with the rest of CSS, it is useful to define how the rule should be parsed and interpreted. In this release, a new customAtRules
option has been added to the API to enable just that.
For example, here is how you could define an @mixin
rule which expects a custom identifier as its prelude, and a style-block as its body. This allows nesting declarations and rules just like other at-rules like @media
and @supports
.
{
customAtRules: {
mixin: {
prelude: '<custom-ident>',
body: 'style-block'
}
}
}
With that, you can parse code like this:
@mixin foo {
color: red;
&.bar {
color: green;
}
}
Lightning CSS also validates the code and will emit syntax errors when it doesn't conform to the syntax definition. Another nice part is that we use this definition to automatically infer the TypeScript types for these rules when used in custom visitors.
<img src="https://user-images.githubusercontent.com/19409/218497162-a0acfb24-6351-4c46-8ff7-1bd20e3c6ff6.jpeg" height="400">Check out the documentation to learn more!
raw
property on returned declarations in visitors (#385)raw
values in visitors that return tokens (f9ed30f9ed8399d1599a9724eb55ce7e0c0ee8ba)substitute_variables
function to UnparsedProperty
in the Rust API (#388)Implement Property::set_prefix
function (a19228dcda0cc0fa6a98f1c9ab19829d9f8c0584)@layer
rules (6419d542bad89b4f64dcf5a2f481a4e6b6d8a7a9):scope
(44434116f4a0f0182a041971028b6cc729ecadc4)<layer-name>
should be escaped (#383):is
, :where
, and :has
(31fc453d9031f5fb4592ee92cd430e31c82697d5):host
and ::slotted
selectors (482fc40358819c3e006f8c20ffb7e4bce2e1fd05)currentColor
(fcf41273a806e9c9245f7ce87c87d69b14a98603)Readme
An extremely fast CSS parser, transformer, and minifier written in Rust. Use it with Parcel, as a standalone library or CLI, or via a plugin with any other tool.
calc()
expressions where possible.color-mix()
functionlab(from purple calc(l * .8) a b)
lab()
, lch()
, oklab()
, and oklch()
colorscolor()
function supporting predefined color spaces such as display-p3
and xyz
rgb
and hsl
functionshwb()
color syntax#rgba
and #rrggbbaa
hex colors:not
with multiple arguments:lang
with multiple arguments:dir
:is
red 40% 80%
)clamp()
, round()
, rem()
, and mod()
math functionsplace-items
)overflow
shorthand@media (width <= 100px)
or @media (100px < width < 500px)
)display
property (e.g. inline flex
)system-ui
font family fallbacks@keyframes
names, grid lines/areas, @counter-style
names, etc.:local()
and :global()
selectorscomposes
propertyLightning CSS can be used from Parcel, as a standalone library from JavaScript or Rust, using a standalone CLI, or wrapped as a plugin within any other tool. See the Lightning CSS website for documentation.
$ node bench.js bootstrap-4.css
cssnano: 544.809ms
159636 bytes
esbuild: 17.199ms
160332 bytes
lightningcss: 4.16ms
143091 bytes
$ node bench.js animate.css
cssnano: 283.105ms
71723 bytes
esbuild: 11.858ms
72183 bytes
lightningcss: 1.973ms
23666 bytes
$ node bench.js tailwind.css
cssnano: 2.198s
1925626 bytes
esbuild: 107.668ms
1961642 bytes
lightningcss: 43.368ms
1824130 bytes
For more benchmarks comparing more tools and input, see here. Note that some of the tools shown perform unsafe optimizations that may change the behavior of the original CSS in favor of smaller file size. Lightning CSS does not do this – the output CSS should always behave identically to the input. Keep this in mind when comparing file sizes between tools.
FAQs
A CSS parser, transformer, and minifier written in Rust
The npm package lightningcss-cli receives a total of 517 weekly downloads. As such, lightningcss-cli popularity was classified as not popular.
We found that lightningcss-cli demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.