Windi CSS
Windi CSS was an on-demand, utility-first CSS framework designed as a performant alternative to Tailwind CSS, aiming to address compilation speed issues in larger projects by providing quicker hot module replacement (HMR) and eliminating the need for production purging. It dynamically scanned HTML and CSS to generate utilities. The project officially announced its deprecation in March 2022, recommending users migrate to Tailwind CSS v3 or newer. While its last stable version, 3.5.6, included some Tailwind v3 utility classes and bug fixes, no further active development, new features, or security updates are expected. Key differentiators during its active period included its 'on-demand' compilation approach and extensive framework integrations.
Common errors
-
Maximum call stack size exceeded at guessClassName
cause An issue within the internal class parsing logic, especially with complex or deeply nested utility classes.fixUpdate Windi CSS to version 3.4.3 or higher, where this bug was addressed. -
Windi CSS Preflight styles not applying when using CLI
cause A bug in the CLI integration prevented the preflight base styles from being correctly injected into the generated CSS.fixUpgrade Windi CSS to version 3.4.4 or newer to resolve the Preflight CLI issue. -
ClassParser incorrectly end group with jsx functional component content
cause Parsing error when Windi CSS encountered specific patterns within JSX functional components, leading to incorrect utility class extraction.fixUpdate Windi CSS to version 3.4.3 or higher to fix the ClassParser issue with JSX content.
Warnings
- breaking Windi CSS has been officially deprecated and is no longer actively maintained. The project announced its deprecation in March 2022, recommending users migrate to Tailwind CSS v3 or newer. New features, bug fixes, and security updates are not expected.
- gotcha While Windi CSS aimed for compatibility with Tailwind CSS v2.0 and later added some Tailwind v3 utility classes, it does not guarantee full feature parity with the latest versions of Tailwind CSS. Users might encounter missing features or subtle behavioral differences compared to official Tailwind CSS.
- gotcha Recent minor versions (v3.5.x) included fixes related to 'renamed colors' and 'default colors provided by Tailwind CSS v3'. If you rely on custom color palettes or older Tailwind v2 color names, these updates might subtly change your output without explicit configuration.
- gotcha Windi CSS is primarily designed to be integrated via bundler-specific plugins (e.g., for Vite, Webpack, Rollup, Nuxt). While a programmatic API exists, direct manual integration into a build pipeline without these plugins can be more complex and prone to misconfiguration.
Install
-
npm install windicss -
yarn add windicss -
pnpm add windicss
Imports
- Processor
const Processor = require('windicss').Processorimport { Processor } from 'windicss' - HTMLParser
const { HTMLParser } = require('windicss')import { HTMLParser } from 'windicss' - generate
const { generate } = require('windicss')import { generate } from 'windicss'
Quickstart
import { Processor, HTMLParser } from 'windicss';
import { readFileSync, writeFileSync } from 'fs';
import { resolve } from 'path';
async function generateWindiCSS() {
const htmlContent = `
<div class="p-4 bg-blue-500 text-white rounded shadow-lg">
<h1 class="text-2xl font-bold mb-2">Hello Windi CSS!</h1>
<p class="text-sm">This is a paragraph with some utility classes.</p>
<button class="px-3 py-2 bg-green-500 hover:bg-green-600 rounded">Click Me</button>
</div>
`;
// Initialize the Windi CSS processor
const processor = new Processor();
// Parse HTML to extract utility classes
const htmlParser = new HTMLParser(htmlContent);
const { classes } = htmlParser.parseClasses();
// Interpret the extracted classes to generate Windi CSS utilities
const interpreted = processor.interpret(classes.join(' '));
// Generate the actual CSS
const { css } = await interpreted.generate();
// Optionally, include preflight base styles
const preflightSheet = processor.preflight();
const preflightCSS = preflightSheet.build();
const finalCSS = `${preflightCSS}\n${css}`;
const outputPath = resolve('./dist/windicss-output.css');
writeFileSync(outputPath, finalCSS);
console.log(`Windi CSS generated and written to ${outputPath}`);
}
generateWindiCSS().catch(console.error);