LightningCSS: High-Performance CSS Toolchain for Linux ARM
LightningCSS is an extremely fast CSS parser, transformer, minifier, and bundler written in Rust, designed for high-performance frontend build processes. The package `lightningcss-linux-arm-gnueabihf` specifically provides the native binary for ARMv7 Linux systems, enabling the core `lightningcss` library to execute its high-performance Rust logic on this architecture. The current stable version is 1.32.0, with frequent minor and patch releases. A key differentiator is its speed, often being over 100x faster than comparable JavaScript-based tools, capable of minifying millions of lines of code per second. It supports modern CSS features like nesting, container queries, view transitions, high gamut color spaces, and custom media queries, automatically transpiling them for specified browser targets using Browserslist configuration.
Common errors
-
Error: Cannot find module '../lightningcss.darwin-arm64.node' (or similar platform-specific .node file)
cause The native binary for LightningCSS specific to your operating system and architecture was not found or correctly loaded, often due to an incomplete or incorrect `npm install` for native modules.fixFirst, clear your `node_modules` and `package-lock.json` (or `yarn.lock`) and then reinstall: `rm -rf node_modules package-lock.json && npm install`. If the problem persists, verify your Node.js version is compatible and consider checking for specific OS dependencies like `VC_redist` on Windows. -
Error [ERR_REQUIRE_ESM]: require() of ES Module <path>/lightningcss/node/index.js not supported
cause You are attempting to use `require()` to import LightningCSS, but it is primarily an ES Module (ESM). CommonJS `require()` cannot directly load ESM modules.fixUpdate your import statements from `const { transform } = require('lightningcss');` to `import { transform } from 'lightningcss';`. Ensure your project's `package.json` either specifies `"type": "module"` or uses `.mjs` file extensions for ESM.
Warnings
- breaking In version 1.30.0, the parsing for relative colors was updated to align with the latest CSS spec. This change now supports numbers in addition to percentages and ensures `calc()` expressions within colors are always treated as numbers. Code relying on previous relative color calculations with percentages may need updates to use numbers instead.
- breaking Version 1.30.0 also introduced updates to the CSS nesting implementation to adhere to the latest spec. This change allows for more flexible nesting patterns, including selectors with pseudo-elements and direct nesting of declarations and rules. While generally an improvement, existing CSS with complex nesting might behave differently or require adjustments.
- gotcha Users employing Node.js worker threads on Linux experienced crashes with earlier versions of LightningCSS. This was addressed in v1.30.1. Ensure you are on a compatible version if running LightningCSS within worker threads to prevent unexpected process exits.
- gotcha Custom resolvers for bundling (`bundleAsync` API) and visitor functions for custom transforms received enhancements in v1.32.0 and v1.31.0, respectively. While these add powerful capabilities (e.g., marking imports as external, adding dependencies), users with existing custom logic should verify compatibility and consider leveraging new features for improved control.
- gotcha As `lightningcss-linux-arm-gnueabihf` is a platform-specific native binding, incorrect environment setup or `npm` configuration can lead to runtime errors where the native module cannot be found. This is a common issue for native Node.js modules, especially on ARM platforms or when `npm` fails to install the correct binary.
Install
-
npm install lightningcss-linux-arm-gnueabihf -
yarn add lightningcss-linux-arm-gnueabihf -
pnpm add lightningcss-linux-arm-gnueabihf
Imports
- transform
const { transform } = require('lightningcss');import { transform } from 'lightningcss'; - bundle
import bundle from 'lightningcss';
import { bundle } from 'lightningcss'; - browserslistToTargets
import { browserslistToTargets } from 'lightningcss'; - Features
import { Features } from 'lightningcss';
Quickstart
import { transform, browserslistToTargets } from 'lightningcss';
import browserslist from 'browserslist';
import { Buffer } from 'node:buffer';
const cssInput = `
@media (width <= 600px) {
.card {
display: grid;
gap: 1rem;
color: oklab(59.686% 0.1009 0.1192);
@nest &::before {
content: 'Mobile view';
}
}
}
.container { width: clamp(200px, 50%, 800px); }
`;
// Define browser targets using browserslist
const targets = browserslistToTargets(browserslist('last 2 versions, > 0.2%'));
try {
const { code, map } = transform({
filename: 'input.css',
code: Buffer.from(cssInput),
minify: true,
sourceMap: true,
targets,
drafts: {
nesting: true,
customMedia: true
}
});
console.log('Transformed and minified CSS:\n', code.toString());
// console.log('Source Map:\n', map?.toString());
// Example for bundling (requires a file on disk)
// import { bundle } from 'lightningcss';
// const { code: bundledCode } = bundle({
// filename: 'path/to/entry.css',
// minify: true,
// targets,
// });
// console.log('Bundled CSS:\n', bundledCode.toString());
} catch (error) {
console.error('Error transforming CSS:', error);
}