Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable optimizeDeps.esbuildOptions.loader #6840

Merged
merged 3 commits into from Apr 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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