LightningCSS (Linux x64 GNU Native Binding)

1.32.0 · active · verified Tue Apr 21

lightningcss-linux-x64-gnu is a platform-specific native Node.js binding for Lightning CSS, an extremely fast CSS parser, transformer, bundler, and minifier written in Rust. It serves as the underlying native module for Linux x64 GNU systems when using the main `lightningcss` npm package. Lightning CSS, currently at version 1.32.0 and released frequently (typically minor versions every few weeks), is known for its exceptional performance, often outperforming JavaScript-based tools by over 100x. Key differentiators include its Rust foundation, browser-grade parsing based on Mozilla's `cssparser` and `selectors` crates, advanced minification techniques (shorthands, merging rules, reducing `calc()` expressions), automatic vendor prefixing, syntax lowering for modern CSS features (like nesting, custom media, high gamut colors) based on `browserslist` targets, and robust support for CSS Modules with local scoping and tree-shaking capabilities. [1, 2, 8, 10, 11]

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to use the `transform` function to minify CSS, apply vendor prefixes, lower syntax (like `oklab` colors and nesting) for specified browser targets, and generate a source map. This example shows processing modern CSS features like nesting and custom media queries. [2, 8, 10, 11]

import { transform, Features } from 'lightningcss';
import { Buffer } from 'node';

const cssInput = `
  @media (width <= 500px) {
    .container {
      display: flex;
      color: oklab(59.686% 0.1009 0.1192);
    }
  }
  .button {
    background-color: #3498db;
    &:hover {
      background-color: darken(#3498db, 10%);
    }
  }
`;

async function processCss() {
  try {
    const { code, map } = transform({
      filename: 'input.css',
      code: Buffer.from(cssInput),
      minify: true,
      sourceMap: true,
      targets: {
        chrome: 100 << 16, // Chrome 100
        firefox: 90 << 16, // Firefox 90
        safari: 15 << 16   // Safari 15
      },
      drafts: { 
        nesting: true, 
        customMedia: true 
      }, // Enable CSS nesting and custom media queries [2, 8, 11]
      // Additional features can be enabled with bitwise OR, e.g., include: Features.Colors
    });

    console.log('Minified CSS:');
    console.log(code.toString());
    console.log('\nSource Map (base64):');
    console.log(map?.toString('base64'));
  } catch (error) {
    console.error('Error processing CSS:', error);
  }
}

processCss();

view raw JSON →