@@ -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 ) {
@@ -277,6 +280,9 @@ function resolveOutDir(config: Required<PluginConfig>, ssr: boolean): string|und
277280 return path . join ( config . publicDirectory , config . buildDirectory )
278281}
279282
283+ /**
284+ * Resolve the Vite manifest config from the configuration.
285+ */
280286function resolveManifestConfig ( config : ResolvedConfig ) : string | false
281287{
282288 const manifestConfig = config . build . ssr
@@ -293,3 +299,28 @@ function resolveManifestConfig(config: ResolvedConfig): string|false
293299
294300 return manifestConfig
295301}
302+
303+ /**
304+ * Add the Interia helpers to the list of SSR dependencies that aren't externalized.
305+ *
306+ * @see https://vitejs.dev/guide/ssr.html#ssr-externals
307+ */
308+ function noExternalInertiaHelpers ( config : UserConfig ) : true | Array < string | RegExp > {
309+ /* eslint-disable-next-line @typescript-eslint/ban-ts-comment */
310+ /* @ts -ignore */
311+ const userNoExternal = ( config . ssr as SSROptions | undefined ) ?. noExternal
312+ const pluginNoExternal = [ 'laravel-vite-plugin' ]
313+
314+ if ( userNoExternal === true ) {
315+ return true
316+ }
317+
318+ if ( typeof userNoExternal === 'undefined' ) {
319+ return pluginNoExternal
320+ }
321+
322+ return [
323+ ...( Array . isArray ( userNoExternal ) ? userNoExternal : [ userNoExternal ] ) ,
324+ ...pluginNoExternal ,
325+ ]
326+ }
0 commit comments