From 2cf5b9d62360c21773d306d578a81ff925598b39 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Sat, 23 Sep 2023 01:22:01 +1000 Subject: [PATCH] Fix Safari issue with `0.0.0.0` network resolution (#241) --- src/index.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index aaef8be..6ec6d55 100644 --- a/src/index.ts +++ b/src/index.ts @@ -116,6 +116,7 @@ export default function laravel(config: string|string[]|PluginConfig): [LaravelP function resolveLaravelPlugin(pluginConfig: Required): LaravelPlugin { let viteDevServerUrl: DevServerUrl let resolvedConfig: ResolvedConfig + let userConfig: UserConfig const defaultAliases: Record = { '@': '/resources/js', @@ -124,7 +125,8 @@ function resolveLaravelPlugin(pluginConfig: Required): LaravelPlug return { name: 'laravel', enforce: 'post', - config: (userConfig, { command, mode }) => { + config: (config, { command, mode }) => { + userConfig = config const ssr = !! userConfig.build?.ssr const env = loadEnv(mode, userConfig.envDir || process.cwd(), '') const assetUrl = env.ASSET_URL ?? '' @@ -202,7 +204,7 @@ function resolveLaravelPlugin(pluginConfig: Required): LaravelPlug const isAddressInfo = (x: string|AddressInfo|null|undefined): x is AddressInfo => typeof x === 'object' if (isAddressInfo(address)) { - viteDevServerUrl = resolveDevServerUrl(address, server.config) + viteDevServerUrl = resolveDevServerUrl(address, server.config, userConfig) fs.writeFileSync(pluginConfig.hotFile, viteDevServerUrl) setTimeout(() => { @@ -406,7 +408,7 @@ function resolveFullReloadConfig({ refresh: config }: Required): P /** * Resolve the dev server URL from the server address and configuration. */ -function resolveDevServerUrl(address: AddressInfo, config: ResolvedConfig): DevServerUrl { +function resolveDevServerUrl(address: AddressInfo, config: ResolvedConfig, userConfig: UserConfig): DevServerUrl { const configHmrProtocol = typeof config.server.hmr === 'object' ? config.server.hmr.protocol : null const clientProtocol = configHmrProtocol ? (configHmrProtocol === 'wss' ? 'https' : 'http') : null const serverProtocol = config.server.https ? 'https' : 'http' @@ -414,8 +416,9 @@ function resolveDevServerUrl(address: AddressInfo, config: ResolvedConfig): DevS const configHmrHost = typeof config.server.hmr === 'object' ? config.server.hmr.host : null const configHost = typeof config.server.host === 'string' ? config.server.host : null + const sailHost = process.env.LARAVEL_SAIL && ! userConfig.server?.host ? 'localhost' : null const serverAddress = isIpv6(address) ? `[${address.address}]` : address.address - const host = configHmrHost ?? configHost ?? serverAddress + const host = configHmrHost ?? sailHost ?? configHost ?? serverAddress const configHmrClientPort = typeof config.server.hmr === 'object' ? config.server.hmr.clientPort : null const port = configHmrClientPort ?? address.port