mirror of
https://github.com/vitejs/vite.git
synced 2024-11-21 22:59:10 +00:00
fix(optimizer): transpile before calling transformGlobImport
(#8343)
This commit is contained in:
parent
de9f556b7d
commit
1dbc7ccac5
@ -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 {
|
||||
@ -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] = {
|
||||
|
@ -1,4 +1,6 @@
|
||||
<script>
|
||||
type Foo = 'bar';
|
||||
console.log("stuff");
|
||||
|
||||
import.meta.glob('./dedupe.*', { eager: true })
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user