fix(optimizer): transpile before calling transformGlobImport (#8343)

This commit is contained in:
翠 / green 2022-05-27 12:40:18 +09:00 committed by GitHub
parent de9f556b7d
commit 1dbc7ccac5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 4 deletions

View File

@ -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] = {

View File

@ -1,4 +1,6 @@
<script>
type Foo = 'bar';
console.log("stuff");
import.meta.glob('./dedupe.*', { eager: true })
</script>