( chunk: OutputChunk, bundle: OutputBundle, analyzedImportedCssFiles: Map<OutputChunk, string[]>, seenChunks: Set<string> = new Set(), seenCss: Set<string> = new Set(), )
| 353 | * correct files when the same chunk is reached via different entry points. |
| 354 | */ |
| 355 | export function getCssFilesForChunk( |
| 356 | chunk: OutputChunk, |
| 357 | bundle: OutputBundle, |
| 358 | analyzedImportedCssFiles: Map<OutputChunk, string[]>, |
| 359 | seenChunks: Set<string> = new Set(), |
| 360 | seenCss: Set<string> = new Set(), |
| 361 | ): string[] { |
| 362 | if (seenChunks.has(chunk.fileName)) { |
| 363 | return [] |
| 364 | } |
| 365 | seenChunks.add(chunk.fileName) |
| 366 | |
| 367 | if (analyzedImportedCssFiles.has(chunk)) { |
| 368 | const files = analyzedImportedCssFiles.get(chunk)! |
| 369 | const additionals = files.filter((file) => !seenCss.has(file)) |
| 370 | additionals.forEach((file) => seenCss.add(file)) |
| 371 | return additionals |
| 372 | } |
| 373 | |
| 374 | // Collect all CSS from imports (unfiltered for caching, filtered for return) |
| 375 | const allFiles: string[] = [] |
| 376 | const filteredFiles: string[] = [] |
| 377 | chunk.imports.forEach((file) => { |
| 378 | const importee = bundle[file] |
| 379 | if (importee?.type === 'chunk') { |
| 380 | const importeeCss = getCssFilesForChunk( |
| 381 | importee, |
| 382 | bundle, |
| 383 | analyzedImportedCssFiles, |
| 384 | seenChunks, |
| 385 | seenCss, |
| 386 | ) |
| 387 | filteredFiles.push(...importeeCss) |
| 388 | // For cache: use the importee's full cached list |
| 389 | if (analyzedImportedCssFiles.has(importee)) { |
| 390 | allFiles.push(...analyzedImportedCssFiles.get(importee)!) |
| 391 | } else { |
| 392 | allFiles.push(...importeeCss) |
| 393 | } |
| 394 | } |
| 395 | }) |
| 396 | |
| 397 | chunk.viteMetadata!.importedCss.forEach((file) => { |
| 398 | allFiles.push(file) |
| 399 | if (!seenCss.has(file)) { |
| 400 | seenCss.add(file) |
| 401 | filteredFiles.push(file) |
| 402 | } |
| 403 | }) |
| 404 | |
| 405 | analyzedImportedCssFiles.set(chunk, unique(allFiles)) |
| 406 | |
| 407 | return filteredFiles |
| 408 | } |
| 409 | |
| 410 | /** |
| 411 | * Compiles index.html into an entry js module |
no test coverage detected