如何用带有 postcss8 API `Declaration` 的正则表达式替换 `walkDecls`
How to replace `walkDecls` with a regex with postcss8 API `Declaration`
您好 postcss 专家!
我尝试将插件更新为 postcss v8 API。
我找不到如何替换:
root.walkDecls(/^--/, (decl) => {
//…
});
通过新的 Declaration:
条目。
将这个正则表达式放在哪里?
很遗憾,新访客 API 中的正则表达式没有 API。使用:
Declaration (decl) {
if (decl.prop.startsWith('--')) {
…
}
}
在 walkDecls
中传递 RegExp 不会使其更快。它只是语法糖。使用 startsWith
而不是 RegExp 的代码将比旧代码运行得更快一些。
您好 postcss 专家!
我尝试将插件更新为 postcss v8 API。
我找不到如何替换:
root.walkDecls(/^--/, (decl) => {
//…
});
通过新的 Declaration:
条目。
将这个正则表达式放在哪里?
很遗憾,新访客 API 中的正则表达式没有 API。使用:
Declaration (decl) {
if (decl.prop.startsWith('--')) {
…
}
}
在 walkDecls
中传递 RegExp 不会使其更快。它只是语法糖。使用 startsWith
而不是 RegExp 的代码将比旧代码运行得更快一些。