(code, chunk, opts, meta)
| 649 | ...(config.command === 'build' |
| 650 | ? { |
| 651 | async renderChunk(code, chunk, opts, meta) { |
| 652 | let chunkCSS: string | undefined |
| 653 | const renderedModules = new Proxy( |
| 654 | {} as Record<string, RenderedModule | undefined>, |
| 655 | { |
| 656 | get(_target, p) { |
| 657 | for (const name in meta.chunks) { |
| 658 | const modules = meta.chunks[name].modules |
| 659 | const module = modules[p as string] |
| 660 | if (module) { |
| 661 | return module |
| 662 | } |
| 663 | } |
| 664 | }, |
| 665 | }, |
| 666 | ) |
| 667 | // the chunk is empty if it's a dynamic entry chunk that only contains a CSS import |
| 668 | const isJsChunkEmpty = code === '' && !chunk.isEntry |
| 669 | let isPureCssChunk = chunk.exports.length === 0 |
| 670 | const ids = Object.keys(chunk.modules) |
| 671 | for (const id of ids) { |
| 672 | if (styles.has(id)) { |
| 673 | // ?transform-only is used for ?url and shouldn't be included in normal CSS chunks |
| 674 | if (transformOnlyRE.test(id)) { |
| 675 | continue |
| 676 | } |
| 677 | |
| 678 | // If this CSS is scoped to its importers exports, check if those importers exports |
| 679 | // are rendered in the chunks. If they are not, we can skip bundling this CSS. |
| 680 | const cssScopeTo = |
| 681 | this.getModuleInfo(id)?.meta?.vite?.cssScopeTo |
| 682 | if ( |
| 683 | cssScopeTo && |
| 684 | !isCssScopeToRendered(cssScopeTo, renderedModules) |
| 685 | ) { |
| 686 | continue |
| 687 | } |
| 688 | |
| 689 | // a css module contains JS, so it makes this not a pure css chunk |
| 690 | if (cssModuleRE.test(id)) { |
| 691 | isPureCssChunk = false |
| 692 | } |
| 693 | |
| 694 | chunkCSS = (chunkCSS || '') + styles.get(id) |
| 695 | } else if (!isJsChunkEmpty) { |
| 696 | // if the module does not have a style, then it's not a pure css chunk. |
| 697 | // this is true because in the `transform` hook above, only modules |
| 698 | // that are css gets added to the `styles` map. |
| 699 | isPureCssChunk = false |
| 700 | } |
| 701 | } |
| 702 | |
| 703 | const publicAssetUrlMap = publicAssetUrlCache.get(config)! |
| 704 | |
| 705 | // resolve asset URL placeholders to their built file URLs |
| 706 | const resolveAssetUrlsInCss = ( |
| 707 | chunkCSS: string, |
| 708 | cssAssetName: string, |
nothing calls this directly
no test coverage detected