Lightning CSS (Linux x64 Musl)

1.32.0 · active · verified Tue Apr 21

lightningcss is a high-performance CSS parser, transformer, minifier, and bundler written in Rust, designed for speed and efficiency in web development workflows. It provides advanced features like CSS module scoping, browser compatibility targeting, and experimental CSS feature transpilation. This particular package, `lightningcss-linux-x64-musl`, is a platform-specific native addon providing the core Rust-based functionality for Linux x64 systems using the musl libc implementation. It is typically installed as an optional dependency of the main `lightningcss` package, which then dynamically loads the correct native binding for the host environment. The library is actively maintained, with frequent minor releases (often monthly or bi-monthly) incorporating new CSS features, performance improvements, and bug fixes, as evidenced by recent updates to v1.32.0, v1.31.0, and v1.30.0. Its key differentiators are its Rust-native performance, comprehensive CSS spec support, and bundling capabilities.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates basic CSS transformation and minification using `lightningcss`. It includes setting browser targets, generating a source map, and shows a simple custom `@import` resolver. It will utilize the native `lightningcss-linux-x64-musl` build if installed as a dependency of `lightningcss`.

import { transform, browserslistToTargets } from 'lightningcss';
import * as browserslist from 'browserslist';

const cssInput = `
  @import "./base.css";
  :root {
    --primary-color: #007bff;
  }
  .container {
    display: flex;
    gap: 10px;
    @media (min-width: 768px) {
      flex-direction: row;
    }
    @media (max-width: 767px) {
      flex-direction: column;
    }
  }
  .button {
    background-color: var(--primary-color);
    color: white;
    padding: 10px 20px;
    border-radius: 5px;
  }
`;

const targets = browserslistToTargets(browserslist('>= 0.25%'));

async function processCss() {
  try {
    const { code, map } = await transform({
      filename: 'input.css',
      code: Buffer.from(cssInput),
      minify: true,
      sourceMap: true,
      targets,
      cssModules: false,
      // Example custom resolver for @import (synchronous)
      resolver: {
        resolve(specifier, from) {
          if (specifier === './base.css') {
            return {
              filePath: 'base.css',
              contents: Buffer.from('body { margin: 0; }')
            };
          }
          return null;
        }
      }
    });

    console.log('Transformed CSS:\n', code.toString());
    // console.log('Source Map:\n', map?.toString());
  } catch (e) {
    console.error('Error transforming CSS:', e);
  }
}

processCss();

view raw JSON →