-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.js
More file actions
60 lines (56 loc) · 1.8 KB
/
process.js
File metadata and controls
60 lines (56 loc) · 1.8 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
const fs = require('fs');
const postcss = require('postcss');
const purgecss = require('@fullhuman/postcss-purgecss');
const cssFilePath = '/Users/mohin/go/src/github.com/html-render/pkg/template/static/assets/styles/main.css'; // Path to the CSS file
// Read the CSS file
fs.readFile(cssFilePath, 'utf8', (err, css) => {
if (err) {
console.error(`Error reading the CSS file at ${cssFilePath}:`, err);
return;
}
// Define PurgeCSS options
const purgecssOptions = {
content: ['./pkg/**/*.gohtml'], // Update this to the path where your Go HTML templates are located
defaultExtractor: content => {
// This extractor assumes your Go HTML templates use standard HTML structure
// Modify if your templates contain Go-specific syntax that affects class or ID extraction
return content.match(/[\w-/:]+(?<!:)/g) || [];
},
safelist: {
standard: [
'active',
'is-visible',
'is-right-0',
'fserv-field',
'select2-container',
'select2',
'fs-webform-container',
'placeholder',
'fserv-button-submit'
],
deep: [
/^fserv-/
],
greedy: [
// Add any greedy patterns if needed
],
keyframes: true,
}
};
// Process CSS with PostCSS and PurgeCSS
postcss([purgecss(purgecssOptions)])
.process(css, { from: cssFilePath })
.then(result => {
// Write the processed CSS back to the file
fs.writeFile(cssFilePath, result.css, err => {
if (err) {
console.error(`Error writing the processed CSS back to ${cssFilePath}:`, err);
return;
}
console.log('CSS processed successfully!');
});
})
.catch(error => {
console.error('Error during CSS processing with PostCSS and PurgeCSS:', error);
});
});