Skip to content

Commit 2f7d1c1

Browse files
committed
feat: transform import.meta.glob when scan JS/TS #10634
1 parent ee7c28a commit 2f7d1c1

File tree

1 file changed

+11
-1
lines changed
  • packages/vite/src/node/optimizer

1 file changed

+11
-1
lines changed

packages/vite/src/node/optimizer/scan.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ function esbuildScanPlugin(
481481
// for jsx/tsx, we need to access the content and check for
482482
// presence of import.meta.glob, since it results in import relationships
483483
// but isn't crawled by esbuild.
484-
build.onLoad({ filter: JS_TYPES_RE }, ({ path: id }) => {
484+
build.onLoad({ filter: JS_TYPES_RE }, async ({ path: id }) => {
485485
let ext = path.extname(id).slice(1)
486486
if (ext === 'mjs') ext = 'js'
487487

@@ -494,6 +494,16 @@ function esbuildScanPlugin(
494494
config.optimizeDeps?.esbuildOptions?.loader?.[`.${ext}`] ||
495495
(ext as Loader)
496496

497+
if (contents.includes('import.meta.glob')) {
498+
return {
499+
loader,
500+
contents:
501+
(
502+
await transformGlobImport(contents, id, config.root, resolve)
503+
)?.s.toString() || contents
504+
}
505+
}
506+
497507
return {
498508
loader,
499509
contents

0 commit comments

Comments
 (0)