gpt4 book ai didi

javascript - 使用 Node js 将 css 拆分为 2 个 css 文件并返工

转载 作者:行者123 更新时间:2023-11-28 08:34:40 25 4
gpt4 key购买 nike

如何将一个 css 文件拆分为两个,例如:使用 Node js 和 reworkcss/css 生成以下形式的 2 个输出 https://github.com/reworkcss/css

main.css
body{
color: blue;
font-size: 12px;
background-color: red;
}
h1 , div{
color: red;
}

output1.css
body{
font-size: 12px;
background-color: red;
}
output2.css
body{
color: blue;
}
h1 , div{
color: red;
}

最佳答案

使用两个 ast 文件,一个用于 font-sizebackground-color:

{
"type": "stylesheet",
"stylesheet": {
"rules": [
{
"type": "rule",
"selectors": [*],
"declarations": [
{
"type": "declaration",
"property": "font-size",
"value": "",
"position": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 99,
"column": 99
},
"source": "input.css"
}
},
{
"type": "declaration",
"property": "background-color",
"value": "",
"position": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 99,
"column": 99
},
"source": "input.css"
}
],
"position": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 99,
"column": 99
},
"source": "input.css"
}
}
]
}
}

剩下的还有一个:

{
"type": "stylesheet",
"stylesheet": {
"rules": [
{
"type": "rule",
"selectors": [*],
"declarations": [
{
"type": "declaration",
"property": "color",
"value": "",
"position": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 99,
"column": 99
},
"source": "input.css"
}
}
],
"position": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 99,
"column": 99
},
"source": "input.css"
}
}
]
}
}

引用资料

关于javascript - 使用 Node js 将 css 拆分为 2 个 css 文件并返工,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28103894/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com