Skip to content

Commit bf25dfe

Browse files
authored
feat: add purgecss (#1127)
1 parent d3d92e7 commit bf25dfe

5 files changed

+225
-20
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ dist-ssr
2222
*.njsproj
2323
*.sln
2424
*.sw?
25+
/debug_rejected.css

package-lock.json

+189
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"generate:parse-options": "node scripts/generateParseOptions.js",
1515
"generate:tailwind": "tailwindcss -i ./src/tailwind.css -o ./src/components/Editor/tailwind.generated.css --full --minify",
1616
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives",
17-
"postbuild": "npm run copy",
17+
"postbuild": "npm run copy && node purgecss.js",
1818
"prepare": "husky",
1919
"preview": "vite preview"
2020
},
@@ -71,6 +71,7 @@
7171
"sass": "^1.81.0",
7272
"tailwindcss": "^3.4.17",
7373
"typescript": "^5.7.2",
74+
"purgecss": "7.0.2",
7475
"vite": "^6.0.2"
7576
}
7677
}

purgecss.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { PurgeCSS } from "purgecss";
2+
3+
import { writeFileSync } from "node:fs";
4+
5+
new PurgeCSS()
6+
.purge({
7+
content: ["./dist/**/*.html", "./dist/**/*.js"],
8+
css: ["./dist/**/*.css"],
9+
defaultExtractor: (content) => content.match(/[\w-/:]+(?<!:)/g) || [],
10+
variables: true,
11+
rejectedCss: true,
12+
safelist: {
13+
standard: [
14+
"md:min-h-[282px]",
15+
"md:w-[100vw]",
16+
"md:w-[376px]",
17+
"md:h-[100vh]",
18+
],
19+
/* Keep density & all color properties/variables */
20+
variables: [/-regular-/, /-default$/, /-hovered$/, /-pressed$/],
21+
/* Some components require a safelist */
22+
greedy: [/db-tabs/],
23+
},
24+
})
25+
.then((purgeCSSResult) => {
26+
for (const result of purgeCSSResult) {
27+
writeFileSync(result.file, result.css);
28+
writeFileSync(`debug_rejected.css`, result.rejectedCss || "");
29+
}
30+
});

tailwind.config.js

+3-19
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,10 @@
1-
/** @type {import('tailwindcss').Config} */
21
import tokens from "@db-ui/foundations/build/tailwind/tailwind-tokens.json";
32

43
export default {
5-
content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"],
6-
safelist: [
7-
{
8-
pattern: /./, // all but colors
9-
},
10-
],
4+
content: ["./index.html", "./src/**/*.{js,jsx,ts,tsx}"],
5+
plugins: [],
116
theme: {
12-
colors: [],
13-
fontFamily: [],
14-
fontSize: [],
15-
screens: {
16-
xs: "360px",
17-
sm: "720px",
18-
md: "1024px",
19-
lg: "1440px",
20-
xl: "1920px",
21-
},
22-
spacing: { 0: 0, ...tokens.spacing },
23-
boxShadow: tokens.elevation,
7+
...tokens,
248
gap: ({ theme }) => ({
259
...theme("spacing"),
2610
}),

0 commit comments

Comments
 (0)