@@ -74,6 +74,7 @@ function serializeElement(element) {
7474export function prerenderPlugin ( { prerenderScript, renderTarget, additionalPrerenderRoutes } = { } ) {
7575 let viteConfig = { } ;
7676 let userEnabledSourceMaps ;
77+ let ssrBuild = false ;
7778
7879 /** @type {import('./types.d.ts').PrerenderedRoute[] } */
7980 let routes = [ ] ;
@@ -127,6 +128,11 @@ export function prerenderPlugin({ prerenderScript, renderTarget, additionalPrere
127128 // Vite is pretty inconsistent with how it resolves config options, both
128129 // hooks are needed to set their respective options. ¯\_(ツ)_/¯
129130 config ( config ) {
131+ if ( config . build ?. ssr ) {
132+ ssrBuild = true
133+ return ;
134+ }
135+
130136 userEnabledSourceMaps = ! ! config . build ?. sourcemap ;
131137
132138 if ( ! config . customLogger ) {
@@ -161,6 +167,7 @@ export function prerenderPlugin({ prerenderScript, renderTarget, additionalPrere
161167 config . build . sourcemap = true ;
162168 } ,
163169 configResolved ( config ) {
170+ if ( ssrBuild ) return ;
164171 // We're only going to alter the chunking behavior in the default cases, where the user and/or
165172 // other plugins haven't already configured this. It'd be impossible to avoid breakages otherwise.
166173 if (
@@ -181,7 +188,7 @@ export function prerenderPlugin({ prerenderScript, renderTarget, additionalPrere
181188 viteConfig = config ;
182189 } ,
183190 async options ( opts ) {
184- if ( ! opts . input ) return ;
191+ if ( ssrBuild || ! opts . input ) return ;
185192 if ( ! prerenderScript ) {
186193 prerenderScript = await getPrerenderScriptFromHTML ( opts . input ) ;
187194 }
@@ -197,6 +204,7 @@ export function prerenderPlugin({ prerenderScript, renderTarget, additionalPrere
197204 } ,
198205 // Injects window checks into Vite's preload helper & modulepreload polyfill
199206 transform ( code , id ) {
207+ if ( ssrBuild ) return ;
200208 if ( id . includes ( preloadHelperId ) ) {
201209 // Injects a window check into Vite's preload helper, instantly resolving
202210 // the module rather than attempting to add a <link> to the document.
@@ -238,6 +246,7 @@ export function prerenderPlugin({ prerenderScript, renderTarget, additionalPrere
238246 }
239247 } ,
240248 async generateBundle ( _opts , bundle ) {
249+ if ( ssrBuild ) return ;
241250 // @ts -ignore
242251 globalThis . location = { } ;
243252 // @ts -ignore
0 commit comments