Skip to content

pantoken / plugins/postcss/flatten-property/src / flattenProperty

变量: flattenProperty

const flattenProperty: {(options?): Plugin; postcss: true; }

Beta

创建 flatten-@property PostCSS 插件。

遍历样式表中所有的 @property at-rule,提取每个 initial-value 描述符,移除 the at-rule,并在前面插入一个包含所有 提取声明的单个 injectSelector { --name: value; … } 规则。移除后留下的空规则和 @layer 块会被丢弃。

Type Declaration

参数

options?

FlattenPropertyOptions

FlattenPropertyOptions.

返回值

Plugin

一个 PostCSS 插件

postcss

postcss: true

所需的 PostCSS 插件标记。

示例

默认注入到 :root

ts
import postcss from "postcss";
import { flattenProperty } from "@pantoken/plugin-flatten-property";

const out = postcss([flattenProperty()]).process(css, { from: undefined }).css;

注入到 :scope(用于 scope 块内)

ts
import postcss from "postcss";
import { flattenProperty } from "@pantoken/plugin-flatten-property";

const out = postcss([flattenProperty({ injectSelector: ":scope" })]).process(css, { from: undefined }).css;
ts
Preserve