-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathpostcss.config.js
53 lines (47 loc) · 1.24 KB
/
postcss.config.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
const path = require("path");
const scopify = require("postcss-scopify");
const { kebabCase } = require("lodash");
function rewriteRootRule() {
return root => {
root.walkRules(rule => {
rule.selectors = rule.selectors.map(selector => {
if (selector === ":root") {
return "&";
}
return selector;
});
});
};
}
function addIdScope() {
return root => {
const filename = root.source.input.file;
const isTailwind = path.basename(path.dirname(filename)) === "tailwind";
if (isTailwind) return scopify("#tailwind")(root);
const basename = path.basename(filename, ".css");
const id = kebabCase(basename);
return scopify(`#${id}`)(root);
};
}
module.exports = {
plugins: [
require("postcss-import"),
require("tailwindcss"),
require("postcss-flexbugs-fixes"),
require("autoprefixer")({ flexbox: "no-2009" }),
require("postcss-merge-selectors")({
matchers: {
active: {
selectorFilter: /(:active|\[data-active\])/,
promote: true,
},
focusVisible: {
selectorFilter: /(:focus-visible|\[data-focus-visible\])/,
promote: true,
},
},
}),
rewriteRootRule(),
addIdScope(),
],
};