Skip to content

Commit

Permalink
feat: transform import.meta.glob when scan JS/TS vitejs#10634
Browse files Browse the repository at this point in the history
  • Loading branch information
candy-Tong committed Oct 25, 2022
1 parent ee7c28a commit 58b8027
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/vite/src/node/optimizer/scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ function esbuildScanPlugin(
// for jsx/tsx, we need to access the content and check for
// presence of import.meta.glob, since it results in import relationships
// but isn't crawled by esbuild.
build.onLoad({ filter: JS_TYPES_RE }, ({ path: id }) => {
build.onLoad({ filter: JS_TYPES_RE }, async ({ path: id }) => {
let ext = path.extname(id).slice(1)
if (ext === 'mjs') ext = 'js'

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

if (contents.includes('import.meta.glob')) {
return {
loader: loader,
contents:
(
await transformGlobImport(contents, id, config.root, resolve)
)?.s.toString() || contents
}
}

return {
loader,
contents
Expand Down

0 comments on commit 58b8027

Please sign in to comment.