-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpurge-css.js
More file actions
68 lines (59 loc) · 1.92 KB
/
purge-css.js
File metadata and controls
68 lines (59 loc) · 1.92 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
import { PurgeCSS } from "purgecss";
import fs from "fs";
async function purgeCSS() {
console.log("🔥 Running PurgeCSS on dist/style.css...");
try {
// Check if the file exists
if (!fs.existsSync("./dist/style.css")) {
console.log("❌ CSS file not found. Build the project first.");
return;
}
const result = await new PurgeCSS().purge({
content: ["./src/**/*.{js,jsx,ts,tsx}", "./index.html"],
css: ["./dist/style.css"],
safelist: {
standard: [
"blocknote-editor",
"blocknote-toolbar",
"ProseMirror",
/^ProseMirror/,
/^blocknote-/,
/^is-/,
/^table-/,
/^dropdown-/,
/^bubble-menu-/,
],
deep: [/hover$/, /focus$/, /active$/, /disabled$/],
greedy: [/ProseMirror/, /blocknote/, /is-active/, /is-dropdown-active/],
},
fontFace: true,
keyframes: true,
variables: true,
});
if (result.length > 0) {
// Get original file size
const originalStats = fs.statSync("./dist/style.css");
const originalSizeInKB = (originalStats.size / 1024).toFixed(2);
// Write optimized CSS
const outputPath = "./dist/style.css";
fs.writeFileSync(outputPath, result[0].css);
// Get new file size
const newStats = fs.statSync(outputPath);
const newSizeInKB = (newStats.size / 1024).toFixed(2);
const reduction = (
(1 - newStats.size / originalStats.size) *
100
).toFixed(2);
console.log(`✅ CSS optimized successfully!`);
console.log(`📊 Original size: ${originalSizeInKB} KB`);
console.log(`📊 Final size: ${newSizeInKB} KB`);
console.log(`🔥 Reduced by: ${reduction}%`);
}
} catch (error) {
console.error("❌ Error optimizing CSS:", error);
}
}
purgeCSS().catch((error) => {
console.error("❌ Error optimizing CSS:", error);
process.exit(1);
});