-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathpostcss.config.js
More file actions
110 lines (100 loc) · 2.74 KB
/
postcss.config.js
File metadata and controls
110 lines (100 loc) · 2.74 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
module.exports = {
plugins: [
{
postcssPlugin: "custom-transforms",
Once(root) {
// Collect all font-face rules
const fontFaceRules = [];
root.walkAtRules("font-face", (rule) => {
fontFaceRules.push(rule);
});
// Remove Lato and Roboto Slab font-face declarations safely
fontFaceRules.forEach((rule) => {
const ruleStr = rule.toString();
if (ruleStr.includes("Lato") || ruleStr.includes("Roboto Slab") || ruleStr.includes("FontAwesome")) {
rule.remove();
}
});
// Add font-display: swap to remaining font-face rules
// Re-collect font-face rules after removals:
const remainingFontFaceRules = [];
root.walkAtRules("font-face", (rule) => {
remainingFontFaceRules.push(rule);
});
remainingFontFaceRules.forEach((rule) => {
let hasDisplay = false;
rule.walkDecls("font-display", () => {
hasDisplay = true;
});
if (!hasDisplay) {
rule.prepend("font-display: swap");
}
});
const fontFaceToWrap = [];
root.walkAtRules("font-face", (rule) => {
fontFaceToWrap.push(rule);
});
// Replace font family references
root.walkDecls((decl) => {
if (decl.prop.includes("font-family") || decl.prop.includes("font")) {
decl.value = decl.value.replace(/\bLato\b/g, "ui-sans-serif");
decl.value = decl.value.replace(
/\bRoboto Slab\b/g,
"Rockwell, 'Rockwell Nova','Roboto Slab','DejaVu Serif','Sitka Small',serif",
);
}
});
// Update media query breakpoints
root.walkAtRules("media", (rule) => {
if (rule.params === "(min-width: 1200px)") {
rule.params = "(min-width: 1500px)";
}
if (rule.params === "(min-width: 992px)") {
rule.params = "(min-width: 1192px)";
}
});
root.walkRules((rule) => {
// Keep rules that contain fa-fw to avoid breaking SVG width, some of these uses fa-fw for width control
if (rule.selector.match(/\.fa([srb]?|\-)/) && !rule.selector.includes("fa-fw")) {
rule.remove();
}
});
},
},
require("autoprefixer"),
require("@fullhuman/postcss-purgecss").default({
content: ["output/**/*.html"],
safelist: [
// Font Awesome classes
/^fa-/,
/^fas$/,
/^far$/,
/^fab$/,
/^fa$/,
// Sphinx Design classes
/^sd-/,
// Hub-related classes
/^hub-/,
// Classes that might be added by JS
/^carousel/,
/^active$/,
/^current/,
// Utility classes
/^highlight/,
"nuitka-fa",
"nuitka-fw",
"copybtn",
],
defaultExtractor: (content) => content.match(/[\w-/:]+(?<!:)|\[.+?\]/g) || [],
}),
require("cssnano")({
preset: [
"default",
{
discardComments: { removeAll: true },
normalizeWhitespace: true,
},
],
}),
],
};