-
Notifications
You must be signed in to change notification settings - Fork 20
/
purgecss.config.js
80 lines (72 loc) · 2.01 KB
/
purgecss.config.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
69
70
71
72
73
74
75
76
77
78
79
80
const path = require('path');
// Standard keyword match for React components
class DefaultExtractor {
static extract(content) {
return content.match(/[A-Za-z0-9-_:\/]+/g) || [];
}
}
// Scan frontmatter in Markdown docs for icons that they use, e.g. "icon: database"
class IconExtractor {
static extract(content) {
const selectors = [`fa-file-alt`]
const matches = content.match(/icon(Brand)?: ([a-zA-Z0-9_-]+)/);
if (matches) {
const isBrand = typeof matches[1] !== 'undefined';
selectors.push(isBrand ? 'fab' : 'fas');
selectors.push(`fa-${matches[2]}`);
}
return selectors;
}
}
// Classes that are added at build time need to be explicitly ignored
const whitelist = [
// Algolia
'algolia-autocomplete',
// Syntax highlighting
'pre',
'code',
// Icon classes used in nodes.ts
'far',
'fa-calendar',
'fa-check-circle',
'fa-times-circle',
];
const whitelistPatterns = [
/^callout-/,
/^DocSearch-/,
];
const whitelistPatternsChildren = [
/^table/,
];
module.exports = {
printRejected: false,
whitelist,
whitelistPatterns,
whitelistPatternsChildren,
// Don't try to purge any CSS in the thirdparty libraries that do their own rendering
// (syntax highlight, Algolia)
ignore: [
'prismjs/',
'@docsearch/',
],
content: [
// All the markdown in the git repos
path.join(process.cwd(), '.cache/gatsby-source-git/**/*.md'),
// Components
path.join(process.cwd(), 'src/components/!(*.d).{ts,js,jsx,tsx}'),
// Static pages (e.g. 404)
path.join(process.cwd(), 'src/pages/!(*.d).{ts,js,jsx,tsx}'),
// Page templates
path.join(process.cwd(), 'src/templates/!(*.d).{ts,js,jsx,tsx}'),
],
extractors : [
{
extractor: DefaultExtractor,
extensions: ['js', 'ts', 'jsx', 'tsx'],
},
{
extractor: IconExtractor,
extensions: ['md']
}
],
};