@@ -4,7 +4,9 @@ const defaultOptions = {
4
4
purgecss : {
5
5
enabled : true ,
6
6
7
- /* Valid PurgeCss config options */
7
+ /**
8
+ * Valid PurgeCss config options
9
+ */
8
10
purgecssOptions : { }
9
11
} ,
10
12
}
@@ -21,48 +23,71 @@ const plugin = (options = {}, context) => {
21
23
/**
22
24
* Only run purge css in production.
23
25
*/
24
- if ( isProd && purgecss . enabled ) plugins . push ( require ( "@fullhuman/postcss-purgecss" ) ( {
25
- content : [
26
- `${ cwd } /.vuepress/theme/**/*.*` ,
27
- `${ cwd } /!(node_modules)/**/*.md` ,
28
- ] ,
29
-
30
- extractors : [
31
- {
32
- /**
33
- * A fix for purge css to pick up class names with escaped chars
34
- * E.g. md:w-1/2.
35
- *
36
- * Solution from https://github.com/tailwindcss/tailwindcss/issues/391#issuecomment-366922730
37
- */
38
- extractor : class TailwindExtractor {
39
- static extract ( content ) {
40
- return (
41
- content . match ( / [ A - z 0 - 9 -:\/ ] + / g) || [ ]
42
- ) ;
43
- }
44
- } ,
45
- extensions : [
46
- "css" ,
47
- "html" ,
48
- "js" ,
49
- "vue" ,
50
- "md" ,
51
- "styl"
52
- ] ,
53
-
54
- /* spread options */
55
- ...purgecss . purgecssOptions ,
56
- }
57
- ] ,
26
+ if ( isProd && purgecss . enabled ) {
58
27
59
28
/**
60
29
* Ensure default resets and normalised classes are not removed by PurgeCSS
61
30
*/
62
- whitelistPatterns : [
31
+ const whitelistPatterns = [
63
32
/ ^ ( h \d | p $ | u l | l i $ | d i v | o l | t a b l e | t d $ | t h $ | t h e a d | t b o d y | m a i n | i n p u t | b u t t o n | f o r m | m d - | h l j s ) /
64
33
]
65
- } ) )
34
+
35
+ /**
36
+ * check if whitelistPatterns already defined then merge it
37
+ */
38
+ if ( purgecss . purgecssOptions . hasOwnProperty ( 'whitelistPatterns' ) ) {
39
+
40
+ purgecss . purgecssOptions . whitelistPatterns = [
41
+ ...whitelistPatterns ,
42
+ ...purgecss . purgecssOptions . whitelistPatterns
43
+ ]
44
+ }
45
+ else {
46
+ purgecss . purgecssOptions . whitelistPatterns = whitelistPatterns
47
+ }
48
+
49
+
50
+ plugins . push ( require ( "@fullhuman/postcss-purgecss" ) ( {
51
+ content : [
52
+ `${ cwd } /.vuepress/theme/**/*.*` ,
53
+ `${ cwd } /!(node_modules)/**/*.md` ,
54
+ ] ,
55
+
56
+ extractors : [
57
+ {
58
+ /**
59
+ * A fix for purge css to pick up class names with escaped chars
60
+ * E.g. md:w-1/2.
61
+ *
62
+ * Solution from https://github.com/tailwindcss/tailwindcss/issues/391#issuecomment-366922730
63
+ */
64
+ extractor : class TailwindExtractor {
65
+ static extract ( content ) {
66
+ return (
67
+ content . match ( / [ A - z 0 - 9 -:\/ ] + / g) || [ ]
68
+ ) ;
69
+ }
70
+ } ,
71
+ extensions : [
72
+ "css" ,
73
+ "html" ,
74
+ "js" ,
75
+ "vue" ,
76
+ "md" ,
77
+ "styl"
78
+ ] ,
79
+
80
+ }
81
+ ] ,
82
+
83
+ /**
84
+ * merge options
85
+ */
86
+ ...purgecss . purgecssOptions
87
+
88
+ } ) )
89
+ }
90
+
66
91
67
92
/**
68
93
* Merge in the site's purgecss config
0 commit comments