包详细信息

tailwind-csstree

humanwhocodes139.2kApache-2.00.1.3

CSSTree syntax for parsing Tailwind custom syntax.

csstree, tailwind, tailwindcss, css

自述文件

Tailwind CSSTree

by Nicholas C. Zakas

If you find this useful, please consider supporting my work with a donation.

Description

Tailwind custom syntax in CSSTree format.

Installation

npm install @humanwhocodes/tailwind-csstree

Usage

This package exports the following objects:

  • tailwind3 - CSSTree syntax extensions for Tailwind 3 syntax
  • tailwind4 - CSSTree syntax extensions for Tailwind 4 syntax

You can import them like this:

import { tailwind3, tailwind4 } from "tailwind-csstree";

Use with ESLint CSS Plugin

To use this package with the ESLint CSS plugin, use languageOptions.customSyntax to specify the Tailwind version you'd like to use in your eslint.config.js file:

// eslint.config.js
import { defineConfig } from "eslint/config";
import css from "@eslint/css";
import { tailwind4 } from "tailwind-csstree";

export default defineConfig([
    {
        files: ["**/*.css"],
        plugins: {
            css,
        },
        language: "css/css",
        languageOptions: {
            customSyntax: tailwind4,
        },
        rules: {
            "css/no-empty-blocks": "error",
        },
    },
]);

Note: Not all ESLint CSS plugin rules will work with Tailwind syntax. That's something I'm actively working on.

Use with CSSTree directly

If you're using CSSTree directly, you

import { fork } from "@eslint/css-tree";
import { tailwind4 } from "tailwind-csstree";

const {
    parse,
    toPlainObject
} = fork(tailwind4);

const result = parse("@config 'tailwind.config.js'");
console.log(toPlainObject(result));

License

Copyright 2025 Nicholas C. Zakas

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

更新日志

Changelog

0.1.3 (2025-08-08)

Bug Fixes

  • parsing [@apply](https://github.com/apply) in Tailwind 4 (#25) (1756fd1)
  • parsing [@source](https://github.com/source) inline() (#26) (94f0966)

0.1.2 (2025-07-25)

Bug Fixes

  • Prevent parsing errors with @import prefix() function in TailwindCSS (#14) (f6123e5)

0.1.1 (2025-06-17)

Bug Fixes

  • Remove accidental bin entry from package.json (9d61c45)

0.1.0 (2025-06-05)

Features

  • Finish up Tailwind 3 compatibility (2fcd25c)
  • Make Tailwind 4 work (91b77a7)
  • Most of Tailwind 3 syntax working (71c8517)
  • Validate -alpha() and --spacing() (dd5bc0e)