( filename: string, type: 'asset' | 'public', hostId: string, hostType: 'js' | 'css' | 'html', config: ResolvedConfig, toRelative: (filename: string, importer: string) => string, )
| 41 | // Duplicated from build.ts in Vite Core, at least while the feature is experimental |
| 42 | // We should later expose this helper for other plugins to use |
| 43 | function toOutputFilePathInHtml( |
| 44 | filename: string, |
| 45 | type: 'asset' | 'public', |
| 46 | hostId: string, |
| 47 | hostType: 'js' | 'css' | 'html', |
| 48 | config: ResolvedConfig, |
| 49 | toRelative: (filename: string, importer: string) => string, |
| 50 | ): string { |
| 51 | const { renderBuiltUrl } = config.experimental |
| 52 | let relative = config.base === '' || config.base === './' |
| 53 | if (renderBuiltUrl) { |
| 54 | const result = renderBuiltUrl(filename, { |
| 55 | hostId, |
| 56 | hostType, |
| 57 | type, |
| 58 | ssr: !!config.build.ssr, |
| 59 | }) |
| 60 | if (typeof result === 'object') { |
| 61 | if (result.runtime) { |
| 62 | throw new Error( |
| 63 | `{ runtime: "${result.runtime}" } is not supported for assets in ${hostType} files: ${filename}`, |
| 64 | ) |
| 65 | } |
| 66 | if (typeof result.relative === 'boolean') { |
| 67 | relative = result.relative |
| 68 | } |
| 69 | } else if (result) { |
| 70 | return result |
| 71 | } |
| 72 | } |
| 73 | if (relative && !config.build.ssr) { |
| 74 | return toRelative(filename, hostId) |
| 75 | } else { |
| 76 | // @ts-expect-error `decodedBase` is internal |
| 77 | return joinUrlSegments(config.decodedBase, filename) |
| 78 | } |
| 79 | } |
| 80 | function getBaseInHTML(urlRelativePath: string, config: ResolvedConfig) { |
| 81 | // Prefer explicit URL if defined for linking to assets and public files from HTML, |
| 82 | // even when base relative is specified |
no test coverage detected