@@ -200,6 +200,29 @@ function esbuildScanPlugin(
200
200
external : ! entries . includes ( path )
201
201
} )
202
202
203
+ const doTransformGlobImport = async (
204
+ contents : string ,
205
+ id : string ,
206
+ loader : Loader
207
+ ) => {
208
+ let transpiledContents
209
+ // transpile because `transformGlobImport` only expects js
210
+ if ( loader !== 'js' ) {
211
+ transpiledContents = ( await transform ( contents , { loader } ) ) . code
212
+ } else {
213
+ transpiledContents = contents
214
+ }
215
+
216
+ const result = await transformGlobImport (
217
+ transpiledContents ,
218
+ id ,
219
+ config . root ,
220
+ resolve
221
+ )
222
+
223
+ return result ?. s . toString ( ) || transpiledContents
224
+ }
225
+
203
226
return {
204
227
name : 'vite:dep-scan' ,
205
228
setup ( build ) {
@@ -305,26 +328,9 @@ function esbuildScanPlugin(
305
328
306
329
const key = `${ path } ?id=${ scriptId ++ } `
307
330
if ( contents . includes ( 'import.meta.glob' ) ) {
308
- let transpiledContents
309
- // transpile because `transformGlobImport` only expects js
310
- if ( loader !== 'js' ) {
311
- transpiledContents = ( await transform ( contents , { loader } ) )
312
- . code
313
- } else {
314
- transpiledContents = contents
315
- }
316
-
317
331
scripts [ key ] = {
318
332
loader : 'js' , // since it is transpiled
319
- contents :
320
- (
321
- await transformGlobImport (
322
- transpiledContents ,
323
- path ,
324
- config . root ,
325
- resolve
326
- )
327
- ) ?. s . toString ( ) || transpiledContents ,
333
+ contents : await doTransformGlobImport ( contents , path , loader ) ,
328
334
pluginData : {
329
335
htmlType : { loader }
330
336
}
@@ -496,11 +502,8 @@ function esbuildScanPlugin(
496
502
497
503
if ( contents . includes ( 'import.meta.glob' ) ) {
498
504
return {
499
- loader,
500
- contents :
501
- (
502
- await transformGlobImport ( contents , id , config . root , resolve )
503
- ) ?. s . toString ( ) || contents
505
+ loader : 'js' , // since it is transpiled,
506
+ contents : await doTransformGlobImport ( contents , id , loader )
504
507
}
505
508
}
506
509
0 commit comments