@@ -2,7 +2,7 @@ import fs from 'fs'
22import { AddressInfo } from 'net'
33import path from 'path'
44import colors from 'picocolors'
5- import { Plugin , loadEnv , UserConfig , ConfigEnv , Manifest , ResolvedConfig } from 'vite'
5+ import { Plugin , loadEnv , UserConfig , ConfigEnv , Manifest , ResolvedConfig , SSROptions } from 'vite'
66
77interface PluginConfig {
88 /**
@@ -99,7 +99,10 @@ export default function laravel(config: string|string[]|PluginConfig): LaravelPl
9999 ...defaultAliases ,
100100 ...userConfig . resolve ?. alias ,
101101 }
102- }
102+ } ,
103+ ssr : {
104+ noExternal : noExternalInertiaHelpers ( userConfig ) ,
105+ } ,
103106 }
104107 } ,
105108 configResolved ( config ) {
@@ -293,3 +296,28 @@ function resolveManifestConfig(config: ResolvedConfig): string|false
293296
294297 return manifestConfig
295298}
299+
300+ /**
301+ * Add the Interia helpers to the list of SSR dependencies that aren't externalized.
302+ *
303+ * @see https://vitejs.dev/guide/ssr.html#ssr-externals
304+ */
305+ function noExternalInertiaHelpers ( config : UserConfig ) : true | Array < string | RegExp > {
306+ /* eslint-disable-next-line @typescript-eslint/ban-ts-comment */
307+ /* @ts -ignore */
308+ const userNoExternal = ( config . ssr as SSROptions | undefined ) ?. noExternal
309+ const pluginNoExternal = [ 'laravel-vite-plugin' ]
310+
311+ if ( userNoExternal === true ) {
312+ return true
313+ }
314+
315+ if ( typeof userNoExternal === 'undefined' ) {
316+ return pluginNoExternal
317+ }
318+
319+ return [
320+ ...( Array . isArray ( userNoExternal ) ? userNoExternal : [ userNoExternal ] ) ,
321+ ...pluginNoExternal ,
322+ ]
323+ }
0 commit comments