MCPcopy
hub / github.com/vitejs/vite / getCssFilesForChunk

Function getCssFilesForChunk

packages/vite/src/node/plugins/html.ts:355–408  ·  view source on GitHub ↗
(
  chunk: OutputChunk,
  bundle: OutputBundle,
  analyzedImportedCssFiles: Map<OutputChunk, string[]>,
  seenChunks: Set<string> = new Set(),
  seenCss: Set<string> = new Set(),
)

Source from the content-addressed store, hash-verified

353 * correct files when the same chunk is reached via different entry points.
354 */
355export 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

Callers 2

html.spec.tsFile · 0.90
getCssTagsForChunkFunction · 0.85

Calls 5

uniqueFunction · 0.90
hasMethod · 0.80
addMethod · 0.80
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected