Skip to content

Commit

Permalink
perf: parallelize await exportsData from depsInfo (#12869)
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework authored Apr 14, 2023
1 parent ca93d67 commit ab3a530
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions packages/vite/src/node/optimizer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -711,23 +711,25 @@ async function prepareEsbuildOptimizerRun(
const { plugins: pluginsFromConfig = [], ...esbuildOptions } =
optimizeDeps?.esbuildOptions ?? {}

for (const id in depsInfo) {
const src = depsInfo[id].src!
const exportsData = await (depsInfo[id].exportsData ??
extractExportsData(src, config, ssr))
if (exportsData.jsxLoader && !esbuildOptions.loader?.['.js']) {
// Ensure that optimization won't fail by defaulting '.js' to the JSX parser.
// This is useful for packages such as Gatsby.
esbuildOptions.loader = {
'.js': 'jsx',
...esbuildOptions.loader,
await Promise.all(
Object.keys(depsInfo).map(async (id) => {
const src = depsInfo[id].src!
const exportsData = await (depsInfo[id].exportsData ??
extractExportsData(src, config, ssr))
if (exportsData.jsxLoader && !esbuildOptions.loader?.['.js']) {
// Ensure that optimization won't fail by defaulting '.js' to the JSX parser.
// This is useful for packages such as Gatsby.
esbuildOptions.loader = {
'.js': 'jsx',
...esbuildOptions.loader,
}
}
}
const flatId = flattenId(id)
flatIdDeps[flatId] = src
idToExports[id] = exportsData
flatIdToExports[flatId] = exportsData
}
const flatId = flattenId(id)
flatIdDeps[flatId] = src
idToExports[id] = exportsData
flatIdToExports[flatId] = exportsData
}),
)

if (optimizerContext.cancelled) return { context: undefined, idToExports }

Expand Down

0 comments on commit ab3a530

Please sign in to comment.