Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat: enable optimizeDeps.esbuildOptions.loader (#6840)
Co-authored-by: bluwy <bjornlu.dev@gmail.com>
  • Loading branch information
dickeylth and bluwy committed Apr 18, 2022
1 parent 694c1ce commit af8ca60
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
5 changes: 3 additions & 2 deletions packages/vite/src/node/optimizer/index.ts
Expand Up @@ -417,11 +417,12 @@ export async function runOptimizeDeps(
try {
exportsData = parse(entryContent) as ExportsData
} catch {
const loader = esbuildOptions.loader?.[path.extname(filePath)] || 'jsx'
debug(
`Unable to parse dependency: ${id}. Trying again with a JSX transform.`
`Unable to parse dependency: ${id}. Trying again with a ${loader} transform.`
)
const transformed = await transformWithEsbuild(entryContent, filePath, {
loader: 'jsx'
loader
})
// Ensure that optimization won't fail by defaulting '.js' to the JSX parser.
// This is useful for packages such as Gatsby.
Expand Down
11 changes: 8 additions & 3 deletions packages/vite/src/node/optimizer/scan.ts
Expand Up @@ -463,21 +463,26 @@ function esbuildScanPlugin(
contents = config.esbuild.jsxInject + `\n` + contents
}

const loader =
config.optimizeDeps?.esbuildOptions?.loader?.[`.${ext}`] ||
(ext as Loader)

if (contents.includes('import.meta.glob')) {
return transformGlob(
contents,
id,
config.root,
ext as Loader,
loader,
resolve,
config.logger
).then((contents) => ({
loader: ext as Loader,
loader,
contents
}))
}

return {
loader: ext as Loader,
loader,
contents
}
})
Expand Down

0 comments on commit af8ca60

Please sign in to comment.