11import { rootRouteId } from '@tanstack/router-core'
22import { VIRTUAL_MODULES } from './virtual-modules'
33import { loadVirtualModule } from './loadVirtualModule'
4- import path from 'node:path'
54
65/**
76 * @description Returns the router manifest that should be sent to the client.
87 * This includes only the assets and preloads for the current route and any
98 * special assets that are needed for the client. It does not include relationships
109 * between routes or any other data that is not needed for the client.
1110 */
12- export async function getStartManifest ( { basePath = '' , routerBasePath} : { basePath ?: string , routerBasePath ?: string } = { } ) {
11+ export async function getStartManifest ( { assetsUrl : maybeAssetsUrl , routerBasePath} : { assetsUrl ?: string , routerBasePath ?: string } = { } ) {
1312 const { tsrStartManifest } = await loadVirtualModule (
1413 VIRTUAL_MODULES . startManifest ,
1514 )
@@ -19,7 +18,9 @@ export async function getStartManifest({basePath = '', routerBasePath}: { basePa
1918 startManifest . routes [ rootRouteId ] || { } )
2019
2120 rootRoute . assets = rootRoute . assets || [ ]
22- let script = `import('${ basePath + "/" + startManifest . clientEntry . replace ( routerBasePath ?? '' , '' ) } ')`
21+ let script =
22+ maybeAssetsUrl ?
23+ `import('${ maybeAssetsUrl + "/" + startManifest . clientEntry . replace ( routerBasePath ?? '' , '' ) } ')` : `import('${ startManifest . clientEntry } ')`
2324 if ( process . env . TSS_DEV_SERVER === 'true' ) {
2425 const { injectedHeadScripts } = await loadVirtualModule (
2526 VIRTUAL_MODULES . injectedHeadScripts ,
@@ -43,20 +44,27 @@ export async function getStartManifest({basePath = '', routerBasePath}: { basePa
4344 routes : Object . fromEntries (
4445 Object . entries ( startManifest . routes ) . map ( ( [ k , v ] ) => {
4546 const { preloads, assets } = v
46- console . log ( { k, preloads, assets} )
47+ if ( ! maybeAssetsUrl ) {
48+ return [
49+ k ,
50+ {
51+ preloads,
52+ assets,
53+ } ,
54+ ]
55+ }
4756 return [
4857 k ,
4958 {
50- preloads : preloads ?. map ( ( url ) => basePath + '/' + url . replace ( routerBasePath ?? '' , '' ) ) || [ ] ,
59+ preloads : preloads ?. map ( ( url ) => maybeAssetsUrl + '/' + url . replace ( routerBasePath ?? '' , '' ) ) || [ ] ,
5160 assets :
5261 assets ?. map ( ( asset ) => {
53- console . log ( asset )
5462 if ( asset . tag === 'link' && asset . attrs ?. href ) {
5563 return {
5664 ...asset ,
5765 attrs : {
5866 ...asset . attrs ,
59- href : basePath + '/' + asset . attrs . href ,
67+ href : maybeAssetsUrl + '/' + asset . attrs . href ,
6068 } ,
6169 }
6270 }
0 commit comments