(options, bundle)
| 822 | }, |
| 823 | |
| 824 | async generateBundle(options, bundle) { |
| 825 | const analyzedImportedCssFiles = new Map<OutputChunk, string[]>() |
| 826 | const inlineEntryChunk = new Set<string>() |
| 827 | const getImportedChunks = ( |
| 828 | chunk: OutputChunk, |
| 829 | seen: Set<string> = new Set(), |
| 830 | ): (OutputChunk | string)[] => { |
| 831 | const chunks: (OutputChunk | string)[] = [] |
| 832 | chunk.imports.forEach((file) => { |
| 833 | const importee = bundle[file] |
| 834 | if (importee) { |
| 835 | if (importee.type === 'chunk' && !seen.has(file)) { |
| 836 | seen.add(file) |
| 837 | |
| 838 | // post-order traversal |
| 839 | chunks.push(...getImportedChunks(importee, seen)) |
| 840 | chunks.push(importee) |
| 841 | } |
| 842 | } else { |
| 843 | // external imports |
| 844 | chunks.push(file) |
| 845 | } |
| 846 | }) |
| 847 | return chunks |
| 848 | } |
| 849 | |
| 850 | const toScriptTag = ( |
| 851 | chunkOrUrl: OutputChunk | string, |
| 852 | toOutputPath: (filename: string) => string, |
| 853 | isAsync: boolean, |
| 854 | ): HtmlTagDescriptor => ({ |
| 855 | tag: 'script', |
| 856 | attrs: { |
| 857 | ...(isAsync ? { async: true } : {}), |
| 858 | type: 'module', |
| 859 | // crossorigin must be set not only for serving assets in a different origin |
| 860 | // but also to make it possible to preload the script using `<link rel="preload">`. |
| 861 | // `<script type="module">` used to fetch the script with credential mode `omit`, |
| 862 | // however `crossorigin` attribute cannot specify that value. |
| 863 | // https://developer.chrome.com/blog/modulepreload/#ok-so-why-doesnt-link-relpreload-work-for-modules:~:text=For%20%3Cscript%3E,of%20other%20modules. |
| 864 | // Now `<script type="module">` uses `same origin`: https://github.com/whatwg/html/pull/3656#:~:text=Module%20scripts%20are%20always%20fetched%20with%20credentials%20mode%20%22same%2Dorigin%22%20by%20default%20and%20can%20no%20longer%0Ause%20%22omit%22 |
| 865 | crossorigin: true, |
| 866 | src: |
| 867 | typeof chunkOrUrl === 'string' |
| 868 | ? chunkOrUrl |
| 869 | : toOutputPath(chunkOrUrl.fileName), |
| 870 | }, |
| 871 | }) |
| 872 | |
| 873 | const toPreloadTag = ( |
| 874 | filename: string, |
| 875 | toOutputPath: (filename: string) => string, |
| 876 | ): HtmlTagDescriptor => ({ |
| 877 | tag: 'link', |
| 878 | attrs: { |
| 879 | rel: 'modulepreload', |
| 880 | crossorigin: true, |
| 881 | href: toOutputPath(filename), |
nothing calls this directly
no test coverage detected