fix(optimizer): transpile before calling transformGlobImport
#8343
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
When
import.meta.glob
is used inside Vue SFC with TypeScript, optimizer fails with error.Minimal reproduction (stackblitz). Run
npx vite optimize
to reproduce.Before #7537, TypeScript was transpiled to JavaScript before passing to
es-module-lexer
.vite/packages/vite/src/node/optimizer/scan.ts
Lines 304 to 317 in b215493
vite/packages/vite/src/node/optimizer/scan.ts
Lines 493 to 507 in b215493
After #7537, the transpilation was removed.
vite/packages/vite/src/node/optimizer/scan.ts
Lines 302 to 313 in 330e0a9
But
parseImportGlob
which is called fromtransformGlobImport
assumes the code as JavaScript. So that transpilation is still needed.vite/packages/vite/src/node/plugins/importMetaGlob.ts
Lines 116 to 122 in 330e0a9
Additional context
Found while testing alpha.4 with my project.😄
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).