@@ -36,6 +36,7 @@ import {
3636 type ResolvedVitePluginConfig ,
3737 resolveReactRouterConfig ,
3838 resolveEntryFiles ,
39+ resolvePublicPath ,
3940} from "../config" ;
4041
4142export async function resolveViteConfig ( {
@@ -150,6 +151,7 @@ export type ReactRouterPluginContext = ReactRouterPluginSsrBuildContext & {
150151 rootDirectory : string ;
151152 entryClientFilePath : string ;
152153 entryServerFilePath : string ;
154+ publicPath : string ;
153155 reactRouterConfig : ResolvedVitePluginConfig ;
154156 viteManifestEnabled : boolean ;
155157} ;
@@ -233,14 +235,14 @@ const getReactRouterManifestBuildAssets = (
233235 ] ) ;
234236
235237 return {
236- module : `${ ctx . reactRouterConfig . publicPath } ${ entryChunk . file } ` ,
238+ module : `${ ctx . publicPath } ${ entryChunk . file } ` ,
237239 imports :
238240 dedupe ( chunks . flatMap ( ( e ) => e . imports ?? [ ] ) ) . map ( ( imported ) => {
239- return `${ ctx . reactRouterConfig . publicPath } ${ viteManifest [ imported ] . file } ` ;
241+ return `${ ctx . publicPath } ${ viteManifest [ imported ] . file } ` ;
240242 } ) ?? [ ] ,
241243 css :
242244 dedupe ( chunks . flatMap ( ( e ) => e . css ?? [ ] ) ) . map ( ( href ) => {
243- return `${ ctx . reactRouterConfig . publicPath } ${ href } ` ;
245+ return `${ ctx . publicPath } ${ href } ` ;
244246 } ) ?? [ ] ,
245247 } ;
246248} ;
@@ -442,6 +444,7 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = (_config) => {
442444 reactRouterConfig,
443445 } ) ;
444446
447+ let publicPath = resolvePublicPath ( viteUserConfig ) ;
445448 let viteManifestEnabled = viteUserConfig . build ?. manifest === true ;
446449
447450 let ssrBuildCtx : ReactRouterPluginSsrBuildContext =
@@ -460,6 +463,7 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = (_config) => {
460463 rootDirectory,
461464 entryClientFilePath,
462465 entryServerFilePath,
466+ publicPath,
463467 viteManifestEnabled,
464468 ...ssrBuildCtx ,
465469 } ;
@@ -507,9 +511,7 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = (_config) => {
507511 export const isSpaMode = ${
508512 ! ctx . reactRouterConfig . ssr && ctx . reactRouterConfig . prerender == null
509513 } ;
510- export const publicPath = ${ JSON . stringify (
511- ctx . reactRouterConfig . publicPath
512- ) } ;
514+ export const publicPath = ${ JSON . stringify ( ctx . publicPath ) } ;
513515 export const entry = { module: entryServer };
514516 export const routes = {
515517 ${ Object . keys ( routes )
@@ -625,7 +627,7 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = (_config) => {
625627 viteConfig . build . assetsDir ,
626628 `manifest-${ version } .js`
627629 ) ;
628- let url = `${ ctx . reactRouterConfig . publicPath } ${ manifestPath } ` ;
630+ let url = `${ ctx . publicPath } ${ manifestPath } ` ;
629631 let nonFingerprintedValues = { url, version } ;
630632
631633 let reactRouterBrowserManifest : ReactRouterManifest = {
@@ -671,7 +673,7 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = (_config) => {
671673 index : route . index ,
672674 caseSensitive : route . caseSensitive ,
673675 module : path . posix . join (
674- ctx . reactRouterConfig . publicPath ,
676+ ctx . publicPath ,
675677 `${ resolveFileUrl (
676678 ctx ,
677679 resolveRelativeRouteFilePath ( route , ctx . reactRouterConfig )
@@ -689,18 +691,18 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = (_config) => {
689691 return {
690692 version : String ( Math . random ( ) ) ,
691693 url : path . posix . join (
692- ctx . reactRouterConfig . publicPath ,
694+ ctx . publicPath ,
693695 VirtualModule . url ( browserManifestId )
694696 ) ,
695697 hmr : {
696698 runtime : path . posix . join (
697- ctx . reactRouterConfig . publicPath ,
699+ ctx . publicPath ,
698700 VirtualModule . url ( injectHmrRuntimeId )
699701 ) ,
700702 } ,
701703 entry : {
702704 module : path . posix . join (
703- ctx . reactRouterConfig . publicPath ,
705+ ctx . publicPath ,
704706 resolveFileUrl ( ctx , ctx . entryClientFilePath )
705707 ) ,
706708 imports : [ ] ,
@@ -1624,15 +1626,15 @@ async function getRouteMetadata(
16241626 index : route . index ,
16251627 caseSensitive : route . caseSensitive ,
16261628 url : path . posix . join (
1627- ctx . reactRouterConfig . publicPath ,
1629+ ctx . publicPath ,
16281630 "/" +
16291631 path . relative (
16301632 ctx . rootDirectory ,
16311633 resolveRelativeRouteFilePath ( route , ctx . reactRouterConfig )
16321634 )
16331635 ) ,
16341636 module : path . posix . join (
1635- ctx . reactRouterConfig . publicPath ,
1637+ ctx . publicPath ,
16361638 `${ resolveFileUrl (
16371639 ctx ,
16381640 resolveRelativeRouteFilePath ( route , ctx . reactRouterConfig )
0 commit comments