-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpostcss.config.js
More file actions
61 lines (54 loc) · 1.57 KB
/
postcss.config.js
File metadata and controls
61 lines (54 loc) · 1.57 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
import postcssSassPlugin from "@csstools/postcss-sass";
import removeEmpty from "postcss-discard-empty";
import postcssFunctions from "postcss-functions";
import postcssSassParser from "postcss-scss";
import {
appendImportantPlugin,
selectorReplacerPlugin,
} from "steam-theming-utils/postcss-plugins";
import fs from "node:fs";
import path from "node:path";
const unquote = (str) => str.replace(/"/g, "");
/**
* @typedef {"mono" | "normal"} IconType
*/
const functions = {
/**
* Output: `file("name"[, "type"])` => `url("data:image/png;base64,${base64}")`
*
* @param {string} name File name without the extension.
* @param {IconType} type
*/
file: (name, type = "normal") => {
const fileName = `${unquote(name)}.png`;
const file = path.join("assets", "icons", unquote(type), fileName);
const base64 = fs.readFileSync(file, { encoding: "base64" });
return `url("data:image/png;base64,${base64}")`;
},
/**
* Output: `icon("name"[, "type"])` => `var(--icon-${type}-${name})`
*
* @param {string} name File name without the extension.
* @param {IconType} type
*/
icon: (name, type = "normal") => {
return `var(--icon-${unquote(type)}-${unquote(name)})`;
},
};
/** @type {import("postcss-load-config").Config} */
export default {
map: false,
parser: postcssSassParser,
plugins: [
postcssFunctions({ functions }),
postcssSassPlugin({
includePaths: ["src"],
silenceDeprecations: ["legacy-js-api", "mixed-decls", "moz-document"],
}),
selectorReplacerPlugin(),
appendImportantPlugin({
filter: [/^(:where\()?:root/],
}),
removeEmpty(),
],
};