Skip to content

Commit

Permalink
fix(manifest): do not fail when using rollupOtions.external (#2532)
Browse files Browse the repository at this point in the history
  • Loading branch information
cawa-93 committed Mar 16, 2021
1 parent fa38f3a commit e44cc11
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions packages/vite/src/node/plugins/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ export function manifestPlugin(config: ResolvedConfig): Plugin {
}
}

function getInternalImports(imports: string[]): string[] {
const filteredImports: string[] = []

for (const file of imports) {
if (bundle[file] === undefined) {
continue
}

filteredImports.push(getChunkName(bundle[file] as OutputChunk))
}

return filteredImports
}

function createChunk(chunk: OutputChunk): ManifestChunk {
const manifestChunk: ManifestChunk = {
file: chunk.fileName
Expand All @@ -58,20 +72,17 @@ export function manifestPlugin(config: ResolvedConfig): Plugin {
}

if (chunk.imports.length) {
const imports = []
for (const file of chunk.imports) {
const importItem = bundle[file]
importItem && imports.push(getChunkName(importItem as OutputChunk))
}
if (imports.length > 0) {
manifestChunk.imports = imports
const internalImports = getInternalImports(chunk.imports)
if (internalImports.length > 0) {
manifestChunk.imports = internalImports
}
}

if (chunk.dynamicImports.length) {
manifestChunk.dynamicImports = chunk.dynamicImports.map((file) =>
getChunkName(bundle[file] as OutputChunk)
)
const internalImports = getInternalImports(chunk.dynamicImports)
if (internalImports.length > 0) {
manifestChunk.dynamicImports = internalImports
}
}

const cssFiles = chunkToEmittedCssFileMap.get(chunk)
Expand Down

0 comments on commit e44cc11

Please sign in to comment.