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

Function toOutputFilePathInJS

packages/vite/src/node/build.ts:1628–1665  ·  view source on GitHub ↗
(
  environment: PartialEnvironment,
  filename: string,
  type: 'asset' | 'public',
  hostId: string,
  hostType: 'js' | 'css' | 'html',
  toRelative: (
    filename: string,
    hostType: string,
  ) => string | { runtime: string },
)

Source from the content-addressed store, hash-verified

1626) => string | { relative?: boolean; runtime?: string } | undefined
1627
1628export function toOutputFilePathInJS(
1629 environment: PartialEnvironment,
1630 filename: string,
1631 type: 'asset' | 'public',
1632 hostId: string,
1633 hostType: 'js' | 'css' | 'html',
1634 toRelative: (
1635 filename: string,
1636 hostType: string,
1637 ) => string | { runtime: string },
1638): string | { runtime: string } {
1639 const { experimental, base, decodedBase } = environment.config
1640 const ssr = environment.config.consumer === 'server' // was !!environment.config.build.ssr
1641 const { renderBuiltUrl } = experimental
1642 let relative = base === '' || base === './'
1643 if (renderBuiltUrl) {
1644 const result = renderBuiltUrl(filename, {
1645 hostId,
1646 hostType,
1647 type,
1648 ssr,
1649 })
1650 if (typeof result === 'object') {
1651 if (result.runtime) {
1652 return { runtime: result.runtime }
1653 }
1654 if (typeof result.relative === 'boolean') {
1655 relative = result.relative
1656 }
1657 } else if (result) {
1658 return result
1659 }
1660 }
1661 if (relative && !ssr) {
1662 return toRelative(filename, hostId)
1663 }
1664 return joinUrlSegments(decodedBase, filename)
1665}
1666
1667export function createToImportMetaURLBasedRelativeRuntime(
1668 format: InternalModuleFormat,

Callers 5

renderAssetUrlInJSFunction · 0.90
generateBundleFunction · 0.90
renderChunkFunction · 0.90
renderChunkFunction · 0.90

Calls 3

joinUrlSegmentsFunction · 0.90
renderBuiltUrlFunction · 0.50
toRelativeFunction · 0.50

Tested by

no test coverage detected