@@ -83,6 +83,8 @@ interface LaravelPlugin extends Plugin {
8383 config : ( config : UserConfig , env : ConfigEnv ) => UserConfig
8484}
8585
86+ type DevServerUrl = `${'http' | 'https' } ://${string } :${number } `
87+
8688let exitHandlersBound = false
8789
8890/**
@@ -100,7 +102,7 @@ export default function laravel(config: string|string[]|PluginConfig): [LaravelP
100102}
101103
102104function resolveLaravelPlugin ( pluginConfig : Required < PluginConfig > ) : LaravelPlugin {
103- let viteDevServerUrl : string
105+ let viteDevServerUrl : DevServerUrl
104106 let resolvedConfig : ResolvedConfig
105107 const cssManifest : Manifest = { }
106108
@@ -169,17 +171,7 @@ function resolveLaravelPlugin(pluginConfig: Required<PluginConfig>): LaravelPlug
169171
170172 const isAddressInfo = ( x : string | AddressInfo | null | undefined ) : x is AddressInfo => typeof x === 'object'
171173 if ( isAddressInfo ( address ) ) {
172- const configHmrProtocol = typeof server . config . server . hmr === 'object' ? server . config . server . hmr . protocol : null
173- const clientHmrProtocol = configHmrProtocol ? ( configHmrProtocol === 'wss' ? 'https' : 'http' ) : null
174- const configProtocol = server . config . server . https ? 'https' : 'http'
175- const protocol = clientHmrProtocol ?? configProtocol
176-
177- const configHmrHost = typeof server . config . server . hmr === 'object' ? server . config . server . hmr . host : null
178- const configHost = typeof server . config . server . host === 'string' ? server . config . server . host : null
179- const serverAddress = address . family === 'IPv6' ? `[${ address . address } ]` : address . address
180- const host = configHmrHost ?? configHost ?? serverAddress
181-
182- viteDevServerUrl = `${ protocol } ://${ host } :${ address . port } `
174+ viteDevServerUrl = resolveDevServerUrl ( address , server . config )
183175 fs . writeFileSync ( hotFile , viteDevServerUrl )
184176
185177 const envDir = resolvedConfig . envDir || process . cwd ( )
@@ -396,6 +388,23 @@ function resolveFullReloadConfig({ refresh: config }: Required<PluginConfig>): P
396388 } )
397389}
398390
391+ /**
392+ * Resolve the dev server URL from the server address and configuration.
393+ */
394+ function resolveDevServerUrl ( address : AddressInfo , config : ResolvedConfig ) : DevServerUrl {
395+ const configHmrProtocol = typeof config . server . hmr === 'object' ? config . server . hmr . protocol : null
396+ const clientProtocol = configHmrProtocol ? ( configHmrProtocol === 'wss' ? 'https' : 'http' ) : null
397+ const serverProtocol = config . server . https ? 'https' : 'http'
398+ const protocol = clientProtocol ?? serverProtocol
399+
400+ const configHmrHost = typeof config . server . hmr === 'object' ? config . server . hmr . host : null
401+ const configHost = typeof config . server . host === 'string' ? config . server . host : null
402+ const serverAddress = address . family === 'IPv6' ? `[${ address . address } ]` : address . address
403+ const host = configHmrHost ?? configHost ?? serverAddress
404+
405+ return `${ protocol } ://${ host } :${ address . port } `
406+ }
407+
399408/**
400409 * Add the Interia helpers to the list of SSR dependencies that aren't externalized.
401410 *
0 commit comments