-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
102 lines (84 loc) · 2.68 KB
/
index.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import { merge } from 'lodash'
const defaultOptions = {
purgecss: {
enabled: true,
/**
* Valid PurgeCss config options
*/
purgecssOptions: {}
},
}
const plugin = (options = {}, context) => {
const { themeConfig, siteConfig, cwd, isProd } = context
const { config, purgecss } = merge(defaultOptions, options)
const plugins = [
require("tailwindcss")(config),
require("autoprefixer"),
]
/**
* Only run purge css in production.
*/
if (isProd && purgecss.enabled) {
/**
* Ensure default resets and normalised classes are not removed by PurgeCSS
*/
const whitelistPatterns = [
/^(h\d|p$|ul|li$|div|ol|table|td$|th$|thead|tbody|main|input|button|form|md-|hljs)/
]
/**
* check if whitelistPatterns already defined then merge it
*/
if (purgecss.purgecssOptions.hasOwnProperty('whitelistPatterns')) {
purgecss.purgecssOptions.whitelistPatterns = [
...whitelistPatterns,
...purgecss.purgecssOptions.whitelistPatterns
]
}
else {
purgecss.purgecssOptions.whitelistPatterns = whitelistPatterns
}
plugins.push(require("@fullhuman/postcss-purgecss")({
content: [
`${cwd}/.vuepress/theme/**/*.*`,
`${cwd}/!(node_modules)/**/*.md`,
],
extractors: [
{
/**
* A fix for purge css to pick up class names with escaped chars
* E.g. md:w-1/2.
*
* Solution from https://github.com/tailwindcss/tailwindcss/issues/391#issuecomment-366922730
*/
extractor: class TailwindExtractor {
static extract(content) {
return (
content.match(/[A-z0-9-:\/]+/g) || []
);
}
},
extensions: [
"css",
"html",
"js",
"vue",
"md",
"styl"
],
}
],
/**
* merge options
*/
...purgecss.purgecssOptions
}))
}
/**
* Merge in the site's purgecss config
*/
siteConfig.postcss = merge(siteConfig.postcss || {}, { plugins })
return {
name: '@silvanite/vuepress-plugin-tailwind',
}
}
export default plugin