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(manifest): do not fail when using rollupOtions.external #2532

Merged
merged 2 commits into from
Mar 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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