@@ -38,6 +38,7 @@ import { rememberCurrentServerEntryImportMtime, startProdServer } from "../serve
3838import { enterPrerenderPhase } from "./prerender-phase.js" ;
3939import { PHASE_PRODUCTION_BUILD } from "vinext/shims/constants" ;
4040import { resolveBuiltRscEntryPath } from "./server-entry.js" ;
41+ import type { VinextRouteRootConfig } from "../config/prerender.js" ;
4142
4243// ─── Progress UI ──────────────────────────────────────────────────────────────
4344
@@ -107,6 +108,8 @@ type RunPrerenderOptions = {
107108 * Intended for tests that build to a custom outDir.
108109 */
109110 rscBundlePath ?: string ;
111+ /** Build output roots captured from the vinext Vite plugin. */
112+ routeRootConfig ?: VinextRouteRootConfig | null ;
110113 /**
111114 * Maximum number of routes rendered in parallel.
112115 * Defaults to prerenderApp/prerenderPages internal defaults when omitted.
@@ -167,7 +170,10 @@ export async function runPrerender(options: RunPrerenderOptions): Promise<Preren
167170 // The manifest lands in dist/server/ alongside the server bundle so it's
168171 // cleaned with the rest of vinext's build output on rebuild and co-located
169172 // with server artifacts.
170- const manifestDir = path . join ( root , "dist" , "server" ) ;
173+ const manifestDir = path . resolve (
174+ root ,
175+ options . routeRootConfig ?. rscOutDir ?? path . join ( "dist" , "server" ) ,
176+ ) ;
171177 const rscBundlePath = options . rscBundlePath ?? resolveBuiltRscEntryPath ( manifestDir ) ;
172178 // The emitted entry may live below dist/server (for example entries/app.js).
173179 // Build metadata and prerender artifacts remain rooted at dist/server.
@@ -221,7 +227,7 @@ export async function runPrerender(options: RunPrerenderOptions): Promise<Preren
221227 const outDir =
222228 mode === "export"
223229 ? path . join ( root , "dist" , "client" )
224- : path . join ( root , "dist" , "server" , "prerendered-routes" ) ;
230+ : path . join ( manifestDir , "prerendered-routes" ) ;
225231
226232 // For hybrid builds (both app/ and pages/ present), start a single shared
227233 // prod server and pass it to both phases. This avoids spinning up two servers
@@ -311,8 +317,7 @@ export async function runPrerender(options: RunPrerenderOptions): Promise<Preren
311317 ...( sharedProdServer
312318 ? { _prodServer : sharedProdServer , _prerenderSecret : sharedPrerenderSecret }
313319 : {
314- pagesBundlePath :
315- options . pagesBundlePath ?? path . join ( root , "dist" , "server" , "entry.js" ) ,
320+ pagesBundlePath : options . pagesBundlePath ?? path . join ( manifestDir , "entry.js" ) ,
316321 } ) ,
317322 onProgress : ( { total, route } ) => {
318323 if ( pagesTotal === 0 ) {
@@ -383,7 +388,7 @@ export async function runPrerender(options: RunPrerenderOptions): Promise<Preren
383388 ) ;
384389 }
385390
386- injectPregeneratedConcretePaths ( root , rscBundlePath ) ;
391+ injectPregeneratedConcretePaths ( root , rscBundlePath , manifestDir ) ;
387392 if ( fs . existsSync ( rscBundlePath ) ) {
388393 rememberCurrentServerEntryImportMtime ( rscBundlePath ) ;
389394 }
0 commit comments