-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path.postcssrc.js
56 lines (50 loc) · 1.21 KB
/
.postcssrc.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
47
48
49
50
51
52
53
54
55
56
const theme = require("./src/theme/theme.js");
const fs = require("fs");
const variablesPath = "./src/theme/autogenerated-variables.css";
[variablesPath].forEach((path) => {
if (fs.existsSync(path)) fs.unlinkSync(path);
});
const flattenObj = (ob) => {
let result = {};
for (const i in ob) {
if (typeof ob[i] === "object" && !Array.isArray(ob[i])) {
const temp = flattenObj(ob[i]);
for (const j in temp) {
result[i + "-" + j] = temp[j];
}
} else {
result[i] = ob[i];
}
}
return result;
};
const transformedTheme = Object.entries(flattenObj(theme)).reduce(
(res, [key, value]) => {
res[`--${key}`] = value;
return res;
},
{}
);
module.exports = {
plugins: {
"postcss-custom-properties": {
exportTo: variablesPath,
importFrom: [
{
customProperties: transformedTheme,
},
],
},
"postcss-custom-media": {
importFrom: [
() => {
const customMedia = {};
Object.entries(theme.breakpoints.values).forEach(([key, value]) => {
customMedia[`--viewport-${key}`] = `(max-width: ${value}px)`;
});
return { customMedia };
},
],
},
},
};