@@ -734,6 +734,7 @@ function updateResultRecord(
734
734
}
735
735
}
736
736
737
+ // eslint-disable-next-line max-lines-per-function
737
738
export async function setupServer (
738
739
serverOptions : NormalizedDevServerOptions ,
739
740
outputFiles : Map < string , OutputFileRecord > ,
@@ -776,6 +777,15 @@ export async function setupServer(
776
777
break ;
777
778
}
778
779
780
+ /**
781
+ * Required when using `externalDependencies` to prevent Vite load errors.
782
+ *
783
+ * @note Can be removed if Vite introduces native support for externals.
784
+ * @note Vite misresolves browser modules in SSR when accessing URLs with multiple segments
785
+ * (e.g., 'foo/bar'), as they are not correctly re-based from the base href.
786
+ */
787
+ const preTransformRequests =
788
+ externalMetadata . explicitBrowser . length === 0 && ssrMode === ServerSsrMode . NoSsr ;
779
789
const cacheDir = join ( serverOptions . cacheOptions . path , serverOptions . buildTarget . project , 'vite' ) ;
780
790
const configuration : InlineConfig = {
781
791
configFile : false ,
@@ -806,15 +816,10 @@ export async function setupServer(
806
816
preserveSymlinks,
807
817
} ,
808
818
dev : {
809
- // This is needed when `externalDependencies` is used to prevent Vite load errors.
810
- // NOTE: If Vite adds direct support for externals, this can be removed.
811
- // NOTE: Vite breaks the resolution of browser modules in SSR
812
- // when accessing a url with two or more segments (e.g., 'foo/bar'),
813
- // as they are not re-based from the base href.
814
- preTransformRequests :
815
- externalMetadata . explicitBrowser . length === 0 && ssrMode === ServerSsrMode . NoSsr ,
819
+ preTransformRequests,
816
820
} ,
817
821
server : {
822
+ preTransformRequests,
818
823
warmup : {
819
824
ssrFiles,
820
825
} ,
0 commit comments