@@ -90,6 +90,10 @@ export async function* serveWithVite(
90
90
serverOptions . servePath = browserOptions . baseHref ;
91
91
}
92
92
93
+ if ( serverOptions . servePath ) {
94
+ serverOptions . servePath = addLeadingSlash ( serverOptions . servePath ) ;
95
+ }
96
+
93
97
// The development server currently only supports a single locale when localizing.
94
98
// This matches the behavior of the Webpack-based development server but could be expanded in the future.
95
99
if (
@@ -591,7 +595,7 @@ export async function setupServer(
591
595
if ( assetSourcePath !== undefined ) {
592
596
// The encoding needs to match what happens in the vite static middleware.
593
597
// ref: https://github.com/vitejs/vite/blob/d4f13bd81468961c8c926438e815ab6b1c82735e/packages/vite/src/node/server/middlewares/static.ts#L163
594
- req . url = `/@fs/${ encodeURI ( assetSourcePath ) } ` ;
598
+ req . url = `${ serverOptions . servePath ?? '' } /@fs/${ encodeURI ( assetSourcePath ) } ` ;
595
599
next ( ) ;
596
600
597
601
return ;
@@ -801,17 +805,15 @@ async function loadViteClientCode(file: string) {
801
805
return contents ;
802
806
}
803
807
804
- function pathnameWithoutServePath ( url : string , serverOptions : NormalizedDevServerOptions ) : string {
808
+ function pathnameWithoutServePath ( url : string , { servePath } : NormalizedDevServerOptions ) : string {
805
809
const parsedUrl = new URL ( url , 'http://localhost' ) ;
806
- let pathname = decodeURIComponent ( parsedUrl . pathname ) ;
807
- if ( serverOptions . servePath && pathname . startsWith ( serverOptions . servePath ) ) {
808
- pathname = pathname . slice ( serverOptions . servePath . length ) ;
809
- if ( pathname [ 0 ] !== '/' ) {
810
- pathname = '/' + pathname ;
811
- }
812
- }
810
+ const pathname = decodeURIComponent ( parsedUrl . pathname ) ;
811
+
812
+ return servePath && pathname . startsWith ( servePath ) ? pathname . slice ( servePath . length ) : pathname ;
813
+ }
813
814
814
- return pathname ;
815
+ function addLeadingSlash ( value : string ) : string {
816
+ return value . charAt ( 0 ) === '/' ? value : '/' + value ;
815
817
}
816
818
817
819
type ViteEsBuildPlugin = NonNullable <
0 commit comments