LightningCSS (Linux ARM64 Musl Native Build)

1.32.0 · active · verified Sun Apr 19

LightningCSS is a high-performance CSS parser, transformer, minifier, and bundler written in Rust, offering significant speed advantages over JavaScript-based alternatives. This particular package, `lightningcss-linux-arm64-musl`, provides the native compiled binary for Linux systems using the ARM64 architecture and Musl C library. It is an optional dependency of the main `lightningcss` package, which automatically installs the correct platform-specific binding. LightningCSS is currently at a stable `1.32.0` release and follows a rapid release cadence, frequently incorporating new CSS features and spec updates. Key differentiators include its Rust-based performance, comprehensive support for modern CSS features like nesting, custom media queries, container queries, relative color syntax, and CSS Modules, as well as robust browser compatibility targeting via Browserslist. While often associated with the Parcel bundler, it is designed for standalone use, making it a versatile tool for optimizing and transpiling CSS in various build workflows. It provides a robust API for programmatic CSS manipulation, including custom resolvers and visitor patterns.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to use `lightningcss` to transform, minify, and transpile CSS code with browser targeting and draft feature enablement.

import { transform, browserslistToTargets } from 'lightningcss';

async function processCss() {
  const cssCode = `
    :root {
      --primary-color: #3498db;
    }
    .container {
      background-color: var(--primary-color);
      display: flex;
      gap: 10px;
      @media (min-width: 768px) {
        flex-direction: row;
      }
    }
    .button {
      padding: 10px 20px;
      color: white;
      background-color: var(--primary-color);
      transition: background-color 0.3s ease-in-out;
      &:hover {
        /* Example of nested selector and a CSS function */
        background-color: color-mix(in srgb, var(--primary-color) 80%, black);
      }
    }
  `;

  // Define target browsers using a Browserslist query
  const targets = browserslistToTargets(['last 2 Chrome versions', 'last 2 Firefox versions', 'Safari >= 15']);

  try {
    const { code, map } = transform({
      filename: 'input.css',
      code: Buffer.from(cssCode),
      minify: true,
      targets,
      // Enable draft features like nesting and custom media queries
      drafts: {
        nesting: true,
        customMedia: true,
      },
      // Uncomment to generate source map
      // sourceMap: true,
      // cssModules: { /* ... options for CSS Modules */ },
    });

    console.log('Minified and Transformed CSS:');
    console.log(code.toString());
    // if (map) {
    //   console.log('\nSource Map:');
    //   console.log(map.toString());
    // }
  } catch (error) {
    console.error('Error processing CSS:', error);
  }
}

processCss();

view raw JSON →