@@ -4,6 +4,7 @@ import type { Options, PublicPluginAPI } from '../types'
44import { existsSync } from 'node:fs'
55import process from 'node:process'
66import chokidar from 'chokidar'
7+ import { glob } from 'tinyglobby'
78import { createUnplugin } from 'unplugin'
89import { createFilter } from 'unplugin-utils'
910import { Context } from './context'
@@ -57,7 +58,7 @@ export default createUnplugin<Options>((options = {}) => {
5758 } ,
5859
5960 vite : {
60- configResolved ( config : ResolvedConfig ) {
61+ async configResolved ( config : ResolvedConfig ) {
6162 ctx . setRoot ( config . root )
6263 ctx . sourcemap = true
6364
@@ -76,7 +77,7 @@ export default createUnplugin<Options>((options = {}) => {
7677 }
7778
7879 if ( config . build . watch && config . command === 'build' )
79- ctx . setupWatcher ( chokidar . watch ( ctx . options . globs ) )
80+ ctx . setupWatcher ( chokidar . watch ( await glob ( ctx . options . globs ) ) )
8081 } ,
8182 configureServer ( server : ViteDevServer ) {
8283 ctx . setupViteServer ( server )
@@ -86,17 +87,20 @@ export default createUnplugin<Options>((options = {}) => {
8687 webpack ( compiler ) {
8788 let watcher : Watching
8889 let fileDepQueue : { path : string , type : 'unlink' | 'add' } [ ] = [ ]
89- compiler . hooks . watchRun . tap ( PLUGIN_NAME , ( ) => {
90+ compiler . hooks . watchRun . tapAsync ( PLUGIN_NAME , async ( ) => {
9091 // ensure watcher is ready(supported since webpack@5.0.0-rc.1)
9192 if ( ! watcher && compiler . watching ) {
9293 watcher = compiler . watching
93- ctx . setupWatcherWebpack ( chokidar . watch ( ctx . options . globs ) , ( path : string , type : 'unlink' | 'add' ) => {
94- fileDepQueue . push ( { path, type } )
95- // process.nextTick is for aggregated file change event
96- process . nextTick ( ( ) => {
97- watcher . invalidate ( )
98- } )
99- } )
94+ ctx . setupWatcherWebpack (
95+ chokidar . watch ( await glob ( ctx . options . globs ) ) ,
96+ ( path : string , type : 'unlink' | 'add' ) => {
97+ fileDepQueue . push ( { path, type } )
98+ // process.nextTick is for aggregated file change event
99+ process . nextTick ( ( ) => {
100+ watcher . invalidate ( )
101+ } )
102+ } ,
103+ )
100104 }
101105 } )
102106 compiler . hooks . compilation . tap ( PLUGIN_NAME , ( compilation ) => {
0 commit comments