@@ -7,11 +7,6 @@ import {
77 resolveManifestCssLink ,
88 rootRouteId ,
99} from '@tanstack/router-core'
10- import {
11- getRouteFilePathsFromModuleIds ,
12- normalizeViteClientBuild ,
13- normalizeViteClientChunk ,
14- } from '../vite/start-manifest-plugin/normalized-client-build'
1510import { processInlineCssUrls } from './inlineCss'
1611import type {
1712 ManifestAssetLink ,
@@ -58,7 +53,6 @@ type DedupeRoute = {
5853export interface StartManifest {
5954 scriptFormat ?: ScriptFormat
6055 routes : Record < string , RouteTreeRoute >
61- clientEntry : string
6256 inlineCss ?: {
6357 styles : Record < string , string >
6458 templates ?: Record < string , InlineCssTemplate >
@@ -187,6 +181,56 @@ function appendRouteStylesheets(
187181 route . css = appendUniqueStylesheets ( route . css , stylesheets )
188182}
189183
184+ function appendRouteScripts (
185+ route : RouteTreeRoute ,
186+ scripts : Array < ManifestScript > ,
187+ ) {
188+ if ( scripts . length === 0 ) {
189+ return
190+ }
191+
192+ route . scripts = [ ...( route . scripts ?? [ ] ) , ...scripts ]
193+ }
194+
195+ function buildScript ( src : string , scriptFormat : ScriptFormat ) : ManifestScript {
196+ return {
197+ attrs : {
198+ ...( scriptFormat === 'module' ? { type : 'module' } : { } ) ,
199+ async : true ,
200+ src,
201+ } ,
202+ }
203+ }
204+
205+ function appendEntryChunkScripts ( options : {
206+ route : RouteTreeRoute
207+ chunk : NormalizedClientChunk
208+ scriptFormat : ScriptFormat
209+ getAssetPath : ( fileName : string ) => string
210+ } ) {
211+ const scripts : Array < ManifestScript > = [ ]
212+
213+ if ( options . scriptFormat === 'iife' ) {
214+ for ( let i = 0 ; i < options . chunk . imports . length ; i ++ ) {
215+ scripts . push (
216+ buildScript (
217+ options . getAssetPath ( options . chunk . imports [ i ] ! ) ,
218+ options . scriptFormat ,
219+ ) ,
220+ )
221+ }
222+ }
223+
224+ scripts . push (
225+ buildScript (
226+ options . getAssetPath ( options . chunk . fileName ) ,
227+ options . scriptFormat ,
228+ ) ,
229+ )
230+
231+ appendRouteScripts ( options . route , scripts )
232+ }
233+
190234function appendAdditionalRouteEntries (
191235 route : RouteTreeRoute ,
192236 entries : ReadonlyArray < AdditionalRouteManifestEntry > ,
@@ -207,9 +251,7 @@ function appendAdditionalRouteEntries(
207251 }
208252
209253 appendRouteStylesheets ( route , stylesheets )
210- if ( scripts . length > 0 ) {
211- route . scripts = [ ...( route . scripts ?? [ ] ) , ...scripts ]
212- }
254+ appendRouteScripts ( route , scripts )
213255}
214256
215257export function buildStartManifest ( options : {
@@ -234,6 +276,13 @@ export function buildStartManifest(options: {
234276 additionalRouteAssets : options . additionalRouteAssets ,
235277 } )
236278
279+ appendEntryChunkScripts ( {
280+ route : routes [ rootRouteId ] ! ,
281+ chunk : scannedChunks . entryChunk ,
282+ scriptFormat : options . scriptFormat ?? 'module' ,
283+ getAssetPath : assetResolvers . getAssetPath ,
284+ } )
285+
237286 dedupeNestedRouteManifestEntries ( rootRouteId , routes [ rootRouteId ] ! , routes )
238287
239288 // Prune routes with no manifest data
@@ -249,7 +298,6 @@ export function buildStartManifest(options: {
249298
250299 const result : StartManifest = {
251300 routes,
252- clientEntry : assetResolvers . getAssetPath ( scannedChunks . entryChunk . fileName ) ,
253301 }
254302
255303 if ( options . scriptFormat === 'iife' ) {
@@ -504,7 +552,7 @@ export function buildRouteManifestRoutes(options: {
504552 for ( const [ routeId , route ] of Object . entries ( options . routeTreeRoutes ) ) {
505553 if ( ! route . filePath ) {
506554 if ( routeId === rootRouteId ) {
507- routes [ routeId ] = route
555+ routes [ routeId ] = { ... route }
508556 continue
509557 }
510558
@@ -513,7 +561,7 @@ export function buildRouteManifestRoutes(options: {
513561
514562 const chunks = options . routeChunksByFilePath . get ( route . filePath )
515563 if ( ! chunks ) {
516- routes [ routeId ] = route
564+ routes [ routeId ] = { ... route }
517565 continue
518566 }
519567
@@ -634,12 +682,6 @@ function mergeReachableHydrationChunkData(options: {
634682 visitStaticChunk ( options . chunk )
635683}
636684
637- export {
638- getRouteFilePathsFromModuleIds ,
639- normalizeViteClientBuild ,
640- normalizeViteClientChunk ,
641- }
642-
643685function dedupeNestedRouteManifestEntries (
644686 routeId : string ,
645687 route : DedupeRoute ,
0 commit comments