-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (40 loc) · 999 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* @type {import('postcss').PluginCreator}
*/
const util = require("postcss-plugin-utilities");
function varToLess(_, variable) {
return "@" + variable.substring(2);
}
module.exports = (opts = {}) => {
// Work with options here
return {
postcssPlugin: "postcss-transform-css-var",
Root(root, postcss) {
// Transform CSS AST here
root.walkRules(":root", (rule) => {
rule.walkDecls((decl) => {
rule.before(decl);
});
rule.remove();
});
root.walkDecls((decl) => {
if (decl.prop.startsWith("--"))
decl.prop = "@" + decl.prop.substring(2);
});
util.parseFunction(root, "var", varToLess);
},
/*
Declaration (decl, postcss) {
// The faster way to find Declaration node
}
*/
/*
Declaration: {
color: (decl, postcss) {
// The fastest way find Declaration node if you know property name
}
}
*/
};
};
module.exports.postcss = true;