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 2 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
11 changes: 8 additions & 3 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,12 +299,17 @@ function esbuildScanPlugin(

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we only transpile if loader !== 'js'?


scripts[key] = {
loader: 'js',
loader: 'js', // since it is transpiled
contents:
(
await transformGlobImport(
contents,
transpiledContents,
path,
config.root,
resolve
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>