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 14, 2022
1 parent 3949d21 commit a3465c7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/vite/src/node/optimizer/index.ts
Expand Up @@ -253,7 +253,10 @@ export async function optimizeDeps(
`Unable to parse dependency: ${id}. Trying again with a JSX transform.`
)
const transformed = await transformWithEsbuild(entryContent, filePath, {
loader: 'jsx'
loader:
(esbuildOptions.loader &&
esbuildOptions.loader[path.extname(filePath)]) ||
'jsx'
})
// 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 @@ -433,8 +433,9 @@ function esbuildScanPlugin(
})
)
}
const { loader } = config.optimizeDeps?.esbuildOptions ?? {}
return {
loader: ext as Loader,
loader: ((loader && loader[`.${ext}`]) || ext) as Loader,
contents
}
})
Expand Down

0 comments on commit a3465c7

Please sign in to comment.