Skip to content

Commit 5cdceeb

Browse files
committed
fix: match optimizer entry by file name than facadeModuleId
1 parent 3802485 commit 5cdceeb

File tree

1 file changed

+24
-27
lines changed
  • packages/vite/src/node/optimizer

1 file changed

+24
-27
lines changed

packages/vite/src/node/optimizer/index.ts

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -610,41 +610,37 @@ export function runOptimizeDeps(
610610
return context
611611
.build()
612612
.then((result) => {
613-
const depsForSrc: Record<string, OptimizedDepInfo[]> = {}
613+
const depForEntryFileName: Record<string, OptimizedDepInfo> = {}
614614
for (const dep of Object.values(depsInfo)) {
615-
if (dep.src) {
616-
// One chunk maybe corresponding multiply entry
617-
depsForSrc[dep.src] ||= []
618-
depsForSrc[dep.src].push(dep)
619-
}
615+
const entryFileName = flattenId(dep.id) + '.js'
616+
depForEntryFileName[entryFileName] = dep
620617
}
621618

622619
for (const chunk of result.output) {
623620
if (chunk.type !== 'chunk') continue
624621

625622
if (chunk.isEntry) {
626-
const deps = depsForSrc[normalizePath(chunk.facadeModuleId!)]
627-
for (const { exportsData, file, id, ...info } of deps) {
628-
addOptimizedDepInfo(metadata, 'optimized', {
623+
const { exportsData, file, id, ...info } =
624+
depForEntryFileName[chunk.fileName]
625+
addOptimizedDepInfo(metadata, 'optimized', {
626+
id,
627+
file,
628+
...info,
629+
// We only need to hash the output.imports in to check for stability, but adding the hash
630+
// and file path gives us a unique hash that may be useful for other things in the future
631+
fileHash: getHash(
632+
metadata.hash + file + JSON.stringify(chunk.modules),
633+
),
634+
browserHash: metadata.browserHash,
635+
// After bundling we have more information and can warn the user about legacy packages
636+
// that require manual configuration
637+
needsInterop: needsInterop(
638+
environment,
629639
id,
630-
file,
631-
...info,
632-
// We only need to hash the output.imports in to check for stability, but adding the hash
633-
// and file path gives us a unique hash that may be useful for other things in the future
634-
fileHash: getHash(
635-
metadata.hash + file + JSON.stringify(chunk.modules),
636-
),
637-
browserHash: metadata.browserHash,
638-
// After bundling we have more information and can warn the user about legacy packages
639-
// that require manual configuration
640-
needsInterop: needsInterop(
641-
environment,
642-
id,
643-
idToExports[id],
644-
chunk,
645-
),
646-
})
647-
}
640+
idToExports[id],
641+
chunk,
642+
),
643+
})
648644
} else {
649645
const id = chunk.fileName.replace(jsExtensionRE, '')
650646
const file = getOptimizedDepPath(environment, id)
@@ -796,6 +792,7 @@ async function prepareRolldownOptimizerRun(
796792
format: 'esm',
797793
sourcemap: true,
798794
dir: processingCacheDir,
795+
entryFileNames: '[name].js',
799796
banner:
800797
platform === 'node'
801798
? `import { createRequire } from 'module';const require = createRequire(import.meta.url);`

0 commit comments

Comments
 (0)