Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(optimizer): transpile before calling transformGlobImport #8343

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 13 additions & 4 deletions packages/vite/src/node/optimizer/scan.ts
Expand Up @@ -3,7 +3,7 @@ import path from 'path'
import { performance } from 'perf_hooks'
import glob from 'fast-glob'
import type { Loader, OnLoadResult, Plugin } from 'esbuild'
import { build } from 'esbuild'
import { build, transform } from 'esbuild'
import colors from 'picocolors'
import type { ResolvedConfig } from '..'
import {
Expand Down Expand Up @@ -299,17 +299,26 @@ function esbuildScanPlugin(

const key = `${path}?id=${scriptId++}`
if (contents.includes('import.meta.glob')) {
let transpiledContents
// transpile because `transformGlobImport` only expects js
if (loader !== 'js') {
transpiledContents = (await transform(contents, { loader }))
.code
} else {
transpiledContents = contents
}

scripts[key] = {
loader: 'js',
loader: 'js', // since it is transpiled
contents:
(
await transformGlobImport(
contents,
transpiledContents,
path,
config.root,
resolve
)
)?.s.toString() || contents
)?.s.toString() || transpiledContents
}
} else {
scripts[key] = {
Expand Down
2 changes: 2 additions & 0 deletions playground/optimize-deps/index.astro
@@ -1,4 +1,6 @@
<script>
type Foo = 'bar';
console.log("stuff");

import.meta.glob('./dedupe.*', { eager: true })
</script>