(html, { chunk, bundle })
| 633 | }, |
| 634 | |
| 635 | transformIndexHtml(html, { chunk, bundle }) { |
| 636 | if (config.build.ssr) return |
| 637 | if (!chunk) return |
| 638 | if (chunk.fileName.includes('-legacy')) { |
| 639 | // The legacy bundle is built first, and its index.html isn't actually emitted if |
| 640 | // modern bundle will be generated. Here we simply record its corresponding legacy chunk. |
| 641 | facadeToLegacyChunkMap.set(chunk.facadeModuleId, chunk.fileName) |
| 642 | if (config.build.chunkImportMap) { |
| 643 | facadeToLegacyImportMap.set( |
| 644 | chunk.facadeModuleId, |
| 645 | bundle![getImportMapFilename(config)]! as Rollup.OutputAsset, |
| 646 | ) |
| 647 | } |
| 648 | if (genModern) { |
| 649 | return |
| 650 | } |
| 651 | } |
| 652 | if (!genModern) { |
| 653 | html = html |
| 654 | .replace(/<script type="module".*?<\/script>/g, '') |
| 655 | .replace(modulePreloadLinkRE, '') |
| 656 | } |
| 657 | |
| 658 | const tags: HtmlTagDescriptor[] = [] |
| 659 | const htmlFilename = chunk.facadeModuleId?.replace(/\?.*$/, '') |
| 660 | |
| 661 | // 1. inject modern polyfills |
| 662 | if (genModern) { |
| 663 | const modernPolyfillFilename = facadeToModernPolyfillMap.get( |
| 664 | chunk.facadeModuleId, |
| 665 | ) |
| 666 | |
| 667 | if (modernPolyfillFilename) { |
| 668 | tags.push({ |
| 669 | tag: 'script', |
| 670 | attrs: { |
| 671 | type: 'module', |
| 672 | crossorigin: true, |
| 673 | src: toAssetPathFromHtml( |
| 674 | modernPolyfillFilename, |
| 675 | chunk.facadeModuleId!, |
| 676 | config, |
| 677 | ), |
| 678 | }, |
| 679 | }) |
| 680 | } else if (modernPolyfills.size) { |
| 681 | throw new Error( |
| 682 | `No corresponding modern polyfill chunk found for ${htmlFilename}`, |
| 683 | ) |
| 684 | } |
| 685 | } |
| 686 | |
| 687 | if (!genLegacy) { |
| 688 | return { html, tags } |
| 689 | } |
| 690 | |
| 691 | // 2. inject importmaps |
| 692 | if (config.build.chunkImportMap) { |
nothing calls this directly
no test coverage detected