Skip to content

Commit e44cc11

Browse files
authored
fix(manifest): do not fail when using rollupOtions.external (#2532)
1 parent fa38f3a commit e44cc11

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

packages/vite/src/node/plugins/manifest.ts

+21-10
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,20 @@ export function manifestPlugin(config: ResolvedConfig): Plugin {
4242
}
4343
}
4444

45+
function getInternalImports(imports: string[]): string[] {
46+
const filteredImports: string[] = []
47+
48+
for (const file of imports) {
49+
if (bundle[file] === undefined) {
50+
continue
51+
}
52+
53+
filteredImports.push(getChunkName(bundle[file] as OutputChunk))
54+
}
55+
56+
return filteredImports
57+
}
58+
4559
function createChunk(chunk: OutputChunk): ManifestChunk {
4660
const manifestChunk: ManifestChunk = {
4761
file: chunk.fileName
@@ -58,20 +72,17 @@ export function manifestPlugin(config: ResolvedConfig): Plugin {
5872
}
5973

6074
if (chunk.imports.length) {
61-
const imports = []
62-
for (const file of chunk.imports) {
63-
const importItem = bundle[file]
64-
importItem && imports.push(getChunkName(importItem as OutputChunk))
65-
}
66-
if (imports.length > 0) {
67-
manifestChunk.imports = imports
75+
const internalImports = getInternalImports(chunk.imports)
76+
if (internalImports.length > 0) {
77+
manifestChunk.imports = internalImports
6878
}
6979
}
7080

7181
if (chunk.dynamicImports.length) {
72-
manifestChunk.dynamicImports = chunk.dynamicImports.map((file) =>
73-
getChunkName(bundle[file] as OutputChunk)
74-
)
82+
const internalImports = getInternalImports(chunk.dynamicImports)
83+
if (internalImports.length > 0) {
84+
manifestChunk.dynamicImports = internalImports
85+
}
7586
}
7687

7788
const cssFiles = chunkToEmittedCssFileMap.get(chunk)

0 commit comments

Comments
 (0)