mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
fix(vite): don't get available port when hmr.server
is set (#27326)
This commit is contained in:
parent
1a57c42223
commit
b8bb1aacd5
@ -171,18 +171,22 @@ export async function buildClient (ctx: ViteBuildContext) {
|
|||||||
}) as any
|
}) as any
|
||||||
|
|
||||||
if (clientConfig.server && clientConfig.server.hmr !== false) {
|
if (clientConfig.server && clientConfig.server.hmr !== false) {
|
||||||
|
const serverDefaults: Omit<ServerOptions, 'hmr'> & { hmr: Exclude<ServerOptions['hmr'], boolean> } = {
|
||||||
|
hmr: {
|
||||||
|
protocol: ctx.nuxt.options.devServer.https ? 'wss' : 'ws',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if (typeof clientConfig.server.hmr !== 'object' || !clientConfig.server.hmr.server) {
|
||||||
const hmrPortDefault = 24678 // Vite's default HMR port
|
const hmrPortDefault = 24678 // Vite's default HMR port
|
||||||
const hmrPort = await getPort({
|
serverDefaults.hmr!.port = await getPort({
|
||||||
port: hmrPortDefault,
|
port: hmrPortDefault,
|
||||||
ports: Array.from({ length: 20 }, (_, i) => hmrPortDefault + 1 + i),
|
ports: Array.from({ length: 20 }, (_, i) => hmrPortDefault + 1 + i),
|
||||||
})
|
})
|
||||||
clientConfig.server = defu(clientConfig.server, <ServerOptions> {
|
}
|
||||||
https: ctx.nuxt.options.devServer.https,
|
if (ctx.nuxt.options.devServer.https) {
|
||||||
hmr: {
|
serverDefaults.https = ctx.nuxt.options.devServer.https === true ? {} : ctx.nuxt.options.devServer.https
|
||||||
protocol: ctx.nuxt.options.devServer.https ? 'wss' : 'ws',
|
}
|
||||||
port: hmrPort,
|
clientConfig.server = defu(clientConfig.server, serverDefaults as ViteConfig['server'])
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add analyze plugin if needed
|
// Add analyze plugin if needed
|
||||||
|
Loading…
Reference in New Issue
Block a user