@parcel/css

A CSS parser, transformer, and minifier written in Rust.

Features

Documentation

@parcel/css can be used from Parcel, as a standalone library from JavaScript or Rust, or wrapped as a plugin within any other tool.

From JavaScript

See the TypeScript definitions for full API docs.

Here is a simple example that compiles the input CSS for Safari 13.2, and minifies the output.

```js const css = require('@parcel/css');

let {code, map} = css.transform({ filename: 'style.css', code: Buffer.from('.foo { color: red }'), minify: true, sourceMap: true, targets: { // Semver versions are represented using a single 24-bit number, with one component per byte. // e.g. to represent 13.2.0, the following could be used. safari: (13 << 16) | (2 << 8) } }); ```

You can also convert the results of running browserslist into targets which can be passed to @parcel/css:

```js const browserslist = require('browserslist'); const css = require('@parcel/css');

let targets = css.browserslistToTargets(browserslist('>= 0.25%')); ```

From Rust

See the Rust API docs on docs.rs.

With Parcel

Add the following to your .parcelrc:

json { "extends": "@parcel/config-default", "optimizers": { "*.css": ["@parcel/optimizer-css"] } }

Benchmarks

``` $ node bench.js bootstrap-4.css cssnano: 542.956ms 159636 bytes

esbuild: 17.411ms 160332 bytes

parcel-css: 4.602ms 143154 bytes

$ node bench.js animate.css cssnano: 283.105ms 71723 bytes

esbuild: 11.858ms 72183 bytes

parcel-css: 1.973ms 23666 bytes

$ node bench.js tailwind.css cssnano: 2.198s 1925626 bytes

esbuild: 107.668ms 1961642 bytes

parcel-css: 43.368ms 1824130 bytes ```