Skip to content

Commit

Permalink
feat:enable-optimizeDeps.esbuildOptions.loader
Browse files Browse the repository at this point in the history
enable respect `optimizeDeps.esbuildOptions.loader` option so that the map of js types to loader could be customized, relevant issue: #3448
  • Loading branch information
dickeylth committed Mar 28, 2022
1 parent 42c15f6 commit e14a1cf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 6 additions & 2 deletions packages/vite/src/node/optimizer/index.ts
Expand Up @@ -412,11 +412,15 @@ export async function runOptimizeDeps(
try {
exportsData = parse(entryContent) as ExportsData
} catch {
const loader =
(esbuildOptions.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
3 changes: 2 additions & 1 deletion packages/vite/src/node/optimizer/scan.ts
Expand Up @@ -476,8 +476,9 @@ function esbuildScanPlugin(
contents
}))
}
const { loader } = config.optimizeDeps?.esbuildOptions ?? {}
return {
loader: ext as Loader,
loader: ((loader && loader[`.${ext}`]) || ext) as Loader,
contents
}
})
Expand Down

0 comments on commit e14a1cf

Please sign in to comment.