@@ -3,6 +3,8 @@ import postcss from 'postcss'
3
3
import purgecss from '@fullhuman/postcss-purgecss'
4
4
import log from '../util/log'
5
5
import htmlTags from 'html-tags'
6
+ import parseGlob from 'parse-glob'
7
+ import path from 'path'
6
8
7
9
function removeTailwindMarkers ( css ) {
8
10
css . walkAtRules ( 'tailwind' , ( rule ) => rule . remove ( ) )
@@ -33,7 +35,7 @@ export function tailwindExtractor(content) {
33
35
return broadMatches . concat ( broadMatchesWithoutTrailingSlash ) . concat ( innerMatches )
34
36
}
35
37
36
- export default function purgeUnusedUtilities ( config , configChanged ) {
38
+ export default function purgeUnusedUtilities ( config , configChanged , registerDependency ) {
37
39
const purgeEnabled = _ . get (
38
40
config ,
39
41
'purge.enabled' ,
@@ -59,6 +61,23 @@ export default function purgeUnusedUtilities(config, configChanged) {
59
61
60
62
const { defaultExtractor, ...purgeOptions } = config . purge . options || { }
61
63
64
+ let content = Array . isArray ( config . purge ) ? config . purge : config . purge . content
65
+
66
+ for ( let maybeGlob of content ) {
67
+ let { is, base } = parseGlob ( maybeGlob )
68
+
69
+ if ( is . glob ) {
70
+ // rollup-plugin-postcss does not support dir-dependency messages
71
+ // but directories can be watched in the same way as files
72
+ registerDependency (
73
+ path . resolve ( base ) ,
74
+ process . env . ROLLUP_WATCH === 'true' ? 'dependency' : 'dir-dependency'
75
+ )
76
+ } else {
77
+ registerDependency ( path . resolve ( maybeGlob ) )
78
+ }
79
+ }
80
+
62
81
return postcss ( [
63
82
function ( css ) {
64
83
const mode = _ . get ( config , 'purge.mode' , 'layers' )
@@ -104,7 +123,7 @@ export default function purgeUnusedUtilities(config, configChanged) {
104
123
} ,
105
124
removeTailwindMarkers ,
106
125
purgecss ( {
107
- content : Array . isArray ( config . purge ) ? config . purge : config . purge . content ,
126
+ content,
108
127
defaultExtractor : ( content ) => {
109
128
const extractor = defaultExtractor || tailwindExtractor
110
129
const preserved = [ ...extractor ( content ) ]
0 commit comments