@@ -3,6 +3,8 @@ import postcss from 'postcss'
33import purgecss from '@fullhuman/postcss-purgecss'
44import log from '../util/log'
55import htmlTags from 'html-tags'
6+ import parseGlob from 'parse-glob'
7+ import path from 'path'
68
79function removeTailwindMarkers ( css ) {
810 css . walkAtRules ( 'tailwind' , ( rule ) => rule . remove ( ) )
@@ -33,7 +35,7 @@ export function tailwindExtractor(content) {
3335 return broadMatches . concat ( broadMatchesWithoutTrailingSlash ) . concat ( innerMatches )
3436}
3537
36- export default function purgeUnusedUtilities ( config , configChanged ) {
38+ export default function purgeUnusedUtilities ( config , configChanged , registerDependency ) {
3739 const purgeEnabled = _ . get (
3840 config ,
3941 'purge.enabled' ,
@@ -59,6 +61,23 @@ export default function purgeUnusedUtilities(config, configChanged) {
5961
6062 const { defaultExtractor, ...purgeOptions } = config . purge . options || { }
6163
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+
6281 return postcss ( [
6382 function ( css ) {
6483 const mode = _ . get ( config , 'purge.mode' , 'layers' )
@@ -104,7 +123,7 @@ export default function purgeUnusedUtilities(config, configChanged) {
104123 } ,
105124 removeTailwindMarkers ,
106125 purgecss ( {
107- content : Array . isArray ( config . purge ) ? config . purge : config . purge . content ,
126+ content,
108127 defaultExtractor : ( content ) => {
109128 const extractor = defaultExtractor || tailwindExtractor
110129 const preserved = [ ...extractor ( content ) ]
0 commit comments