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

Function toOutputFilePathWithoutRuntime

packages/vite/src/node/build.ts:1680–1715  ·  view source on GitHub ↗
(
  filename: string,
  type: 'asset' | 'public',
  hostId: string,
  hostType: 'js' | 'css' | 'html',
  config: ResolvedConfig,
  toRelative: (filename: string, hostId: string) => string,
)

Source from the content-addressed store, hash-verified

1678}
1679
1680export function toOutputFilePathWithoutRuntime(
1681 filename: string,
1682 type: 'asset' | 'public',
1683 hostId: string,
1684 hostType: 'js' | 'css' | 'html',
1685 config: ResolvedConfig,
1686 toRelative: (filename: string, hostId: string) => string,
1687): string {
1688 const { renderBuiltUrl } = config.experimental
1689 let relative = config.base === '' || config.base === './'
1690 if (renderBuiltUrl) {
1691 const result = renderBuiltUrl(filename, {
1692 hostId,
1693 hostType,
1694 type,
1695 ssr: !!config.build.ssr,
1696 })
1697 if (typeof result === 'object') {
1698 if (result.runtime) {
1699 throw new Error(
1700 `{ runtime: "${result.runtime}" } is not supported for assets in ${hostType} files: ${filename}`,
1701 )
1702 }
1703 if (typeof result.relative === 'boolean') {
1704 relative = result.relative
1705 }
1706 } else if (result) {
1707 return result
1708 }
1709 }
1710 if (relative && !config.build.ssr) {
1711 return toRelative(filename, hostId)
1712 } else {
1713 return joinUrlSegments(config.decodedBase, filename)
1714 }
1715}
1716
1717export const toOutputFilePathInCss: typeof toOutputFilePathWithoutRuntime =
1718 toOutputFilePathWithoutRuntime

Callers

nothing calls this directly

Calls 3

joinUrlSegmentsFunction · 0.90
renderBuiltUrlFunction · 0.50
toRelativeFunction · 0.50

Tested by

no test coverage detected