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

fix: enable failing dependencies to be optimised by pre-processing them with esbuild #4275

Merged
merged 6 commits into from Aug 23, 2021
Merged
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
14 changes: 10 additions & 4 deletions packages/vite/src/node/optimizer/index.ts
Expand Up @@ -238,7 +238,7 @@ export async function optimizeDeps(
const idToExports: Record<string, ExportsData> = {}
const flatIdToExports: Record<string, ExportsData> = {}

const { plugins = [], ...esbuildOptions } =
let { plugins = [], ...esbuildOptions } =
config.optimizeDeps?.esbuildOptions ?? {}

await init
Expand All @@ -256,9 +256,15 @@ export async function optimizeDeps(
const transformed = await transformWithEsbuild(entryContent, filePath, {
loader: 'jsx'
})
// Ensure that optimization won't fail.
esbuildOptions.loader ??= {}
esbuildOptions.loader['.js'] ??= 'jsx'
// Ensure that optimization won't fail by defaulting '.js' to the JSX parser.
// This is useful for packages such as Gatsby.
esbuildOptions = {
...esbuildOptions,
aleclarson marked this conversation as resolved.
Show resolved Hide resolved
loader: {
'.js': 'jsx',
...esbuildOptions.loader
}
}
exportsData = parse(transformed.code) as ExportsData
}
for (const { ss, se } of exportsData[0]) {
Expand Down