Skip to content

Commit

Permalink
fix(optimizer): transpile before calling transformGlobImport (#8343)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed May 27, 2022
1 parent de9f556 commit 1dbc7cc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
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>

0 comments on commit 1dbc7cc

Please sign in to comment.