Skip to content

Commit 2cf5b9d

Browse files
authored
Fix Safari issue with 0.0.0.0 network resolution (#241)
1 parent 6b28527 commit 2cf5b9d

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ export default function laravel(config: string|string[]|PluginConfig): [LaravelP
116116
function resolveLaravelPlugin(pluginConfig: Required<PluginConfig>): LaravelPlugin {
117117
let viteDevServerUrl: DevServerUrl
118118
let resolvedConfig: ResolvedConfig
119+
let userConfig: UserConfig
119120

120121
const defaultAliases: Record<string, string> = {
121122
'@': '/resources/js',
@@ -124,7 +125,8 @@ function resolveLaravelPlugin(pluginConfig: Required<PluginConfig>): LaravelPlug
124125
return {
125126
name: 'laravel',
126127
enforce: 'post',
127-
config: (userConfig, { command, mode }) => {
128+
config: (config, { command, mode }) => {
129+
userConfig = config
128130
const ssr = !! userConfig.build?.ssr
129131
const env = loadEnv(mode, userConfig.envDir || process.cwd(), '')
130132
const assetUrl = env.ASSET_URL ?? ''
@@ -202,7 +204,7 @@ function resolveLaravelPlugin(pluginConfig: Required<PluginConfig>): LaravelPlug
202204

203205
const isAddressInfo = (x: string|AddressInfo|null|undefined): x is AddressInfo => typeof x === 'object'
204206
if (isAddressInfo(address)) {
205-
viteDevServerUrl = resolveDevServerUrl(address, server.config)
207+
viteDevServerUrl = resolveDevServerUrl(address, server.config, userConfig)
206208
fs.writeFileSync(pluginConfig.hotFile, viteDevServerUrl)
207209

208210
setTimeout(() => {
@@ -406,16 +408,17 @@ function resolveFullReloadConfig({ refresh: config }: Required<PluginConfig>): P
406408
/**
407409
* Resolve the dev server URL from the server address and configuration.
408410
*/
409-
function resolveDevServerUrl(address: AddressInfo, config: ResolvedConfig): DevServerUrl {
411+
function resolveDevServerUrl(address: AddressInfo, config: ResolvedConfig, userConfig: UserConfig): DevServerUrl {
410412
const configHmrProtocol = typeof config.server.hmr === 'object' ? config.server.hmr.protocol : null
411413
const clientProtocol = configHmrProtocol ? (configHmrProtocol === 'wss' ? 'https' : 'http') : null
412414
const serverProtocol = config.server.https ? 'https' : 'http'
413415
const protocol = clientProtocol ?? serverProtocol
414416

415417
const configHmrHost = typeof config.server.hmr === 'object' ? config.server.hmr.host : null
416418
const configHost = typeof config.server.host === 'string' ? config.server.host : null
419+
const sailHost = process.env.LARAVEL_SAIL && ! userConfig.server?.host ? 'localhost' : null
417420
const serverAddress = isIpv6(address) ? `[${address.address}]` : address.address
418-
const host = configHmrHost ?? configHost ?? serverAddress
421+
const host = configHmrHost ?? sailHost ?? configHost ?? serverAddress
419422

420423
const configHmrClientPort = typeof config.server.hmr === 'object' ? config.server.hmr.clientPort : null
421424
const port = configHmrClientPort ?? address.port

0 commit comments

Comments
 (0)