-
Notifications
You must be signed in to change notification settings - Fork 2
/
process-css.js
68 lines (64 loc) · 1.62 KB
/
process-css.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const fs = require('fs');
const postcss = require('postcss');
const purgecss = require('@fullhuman/postcss-purgecss');
const cssFilePath = './themes/hugo-product-theme/assets/css/main.css'; // Path CSS file
// Read the CSS file
fs.readFile(cssFilePath, (err, css) => {
if (err) throw err;
// Define PurgeCSS options
const purgecssOptions = {
content: ['./hugo_stats.json'], // Paths HTML files or other content files
defaultExtractor: content => {
const els = JSON.parse(content).htmlElements;
return [
...(els.tags || []),
...(els.classes || []),
...(els.ids || []),
];
},
safelist: {
standard: [
'active',
'is-visible',
'is-right-0',
'fserv-field',
'select2-container',
'select2',
'fs-webform-container',
'placeholder',
'fserv-button-submit',
'single-result-item',
'single-result-item h2',
'search-content',
'is-show',
],
deep: [
/^fserv-/,
/^fs-/,
/^select2-/,
/^formserv/,
/^ss-/,
/^owl-/,
/^item/,
/^headroom/,
],
greedy: [
// /^header-/,
],
keyframes: true,
}
};
// Process CSS with PostCSS and PurgeCSS
postcss([purgecss(purgecssOptions)])
.process(css, { from: cssFilePath })
.then(result => {
// Processed CSS back to the file
fs.writeFile(cssFilePath, result.css, err => {
if (err) throw err;
console.error('CSS processed successfully!');
});
})
.catch(error => {
console.error(error);
});
});