@@ -9,12 +9,17 @@ const loaderMatch = /\.data\.(j|t)s$/
9
9
let server : ViteDevServer
10
10
11
11
interface LoaderModule {
12
+ watch : string [ ] | string | undefined
13
+ load : ( ) => any
14
+ }
15
+
16
+ interface CachedLoaderModule {
12
17
base : string
13
- pattern : string | undefined
18
+ pattern : string [ ] | undefined
14
19
loader : ( ) => any
15
20
}
16
21
17
- const idToLoaderModulesMap : Record < string , LoaderModule | undefined > =
22
+ const idToLoaderModulesMap : Record < string , CachedLoaderModule | undefined > =
18
23
Object . create ( null )
19
24
20
25
// During build, the load hook will be called on the same file twice
@@ -50,7 +55,7 @@ export const staticDataPlugin: Plugin = {
50
55
}
51
56
52
57
const base = dirname ( id )
53
- let pattern : string | undefined
58
+ let pattern : string [ ] | undefined
54
59
let loader : ( ) => any
55
60
56
61
const existing = idToLoaderModulesMap [ id ]
@@ -60,10 +65,15 @@ export const staticDataPlugin: Plugin = {
60
65
// use vite's load config util as a away to load Node.js file with
61
66
// TS & native ESM support
62
67
const loaderModule = ( await loadConfigFromFile ( { } as any , id ) )
63
- ?. config as any
64
- pattern = loaderModule . watch
65
- if ( pattern && pattern . startsWith ( './' ) ) {
66
- pattern = pattern . slice ( 2 )
68
+ ?. config as LoaderModule
69
+ pattern =
70
+ typeof loaderModule . watch === 'string'
71
+ ? [ loaderModule . watch ]
72
+ : loaderModule . watch
73
+ if ( pattern ) {
74
+ pattern = pattern . map ( ( p ) => {
75
+ return p . startsWith ( './' ) ? p . slice ( 2 ) : p
76
+ } )
67
77
}
68
78
loader = loaderModule . load
69
79
}
@@ -91,7 +101,7 @@ export const staticDataPlugin: Plugin = {
91
101
const { base, pattern } = idToLoaderModulesMap [ id ] !
92
102
; ( server as any ) . _globImporters [ id ] = {
93
103
module : server . moduleGraph . getModuleById ( id ) ,
94
- importGlobs : [ { base, pattern } ]
104
+ importGlobs : pattern ?. map ( ( pattern ) => ( { base, pattern } ) )
95
105
}
96
106
}
97
107
return null
0 commit comments