-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathpostcss.config.cjs
More file actions
70 lines (63 loc) · 2.18 KB
/
Copy pathpostcss.config.cjs
File metadata and controls
70 lines (63 loc) · 2.18 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
69
70
// eslint-disable-next-line @typescript-eslint/no-var-requires
const purgecssModule = require('@fullhuman/postcss-purgecss');
// Handle default export for CommonJS/ESM interop (runtime check shows it's directly callable)
// TypeScript doesn't recognize CommonJS module exports correctly, so we need to bypass type checking
const purgecssRaw = purgecssModule.default || purgecssModule;
/** @type {any} */
const purgecss = purgecssRaw;
/**
* See Vue guide for extractor and safelist
* https://purgecss.com/guides/vue.html#usage
*
*/
const purgecssConfig = {
content: ['./src/**/*.{vue,js,ts,css,scss,html}'],
extractors: [
{
extractor(content) {
const contentWithoutStyleBlocks = content.replace(/<style[^]+?<\/style>/gi, '');
return contentWithoutStyleBlocks.match(/[A-Za-z0-9-_/:]*[A-Za-z0-9-_/]+/g) || [];
},
extensions: ['vue']
}
],
safelist: [
/-(leave|enter|appear)(|-(to|from|active))$/,
/^(?!(|.*?:)cursor-move).+-move$/,
/^router-link(|-exact)-active$/,
/data-v-.*/,
/data-bs.*/, // Bootstrap 5 javascript data attributes
/driver-.*/,
],
};
// Create a wrapper plugin that conditionally applies PurgeCSS
const conditionalPurgecss = () => {
const purgecssInstance = purgecss(purgecssConfig);
return {
postcssPlugin: 'conditional-purgecss',
Once(root, helpers) {
// Check if this CSS file is from vue-data-ui
const filePath = helpers.result.root.source?.input?.file ||
helpers.result.root.source?.input?.from ||
helpers.result.opts?.from ||
'';
if (filePath.includes('vue-data-ui') || filePath.includes('node_modules/vue-data-ui')) {
// Skip PurgeCSS processing for vue-data-ui files - do nothing
return;
}
// Apply PurgeCSS for all other files
// Pass the full helpers object (includes result, postcss, list, etc.) to the wrapped plugin
if (typeof purgecssInstance === 'function') {
return purgecssInstance(root, helpers);
} else if (purgecssInstance.Once) {
return purgecssInstance.Once(root, helpers);
}
}
};
};
conditionalPurgecss.postcss = true;
module.exports = {
plugins: [
conditionalPurgecss()
]
};