mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 15:15:19 +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
|
||||
|
||||
if (clientConfig.server && clientConfig.server.hmr !== false) {
|
||||
const hmrPortDefault = 24678 // Vite's default HMR port
|
||||
const hmrPort = await getPort({
|
||||
port: hmrPortDefault,
|
||||
ports: Array.from({ length: 20 }, (_, i) => hmrPortDefault + 1 + i),
|
||||
})
|
||||
clientConfig.server = defu(clientConfig.server, <ServerOptions> {
|
||||
https: ctx.nuxt.options.devServer.https,
|
||||
const serverDefaults: Omit<ServerOptions, 'hmr'> & { hmr: Exclude<ServerOptions['hmr'], boolean> } = {
|
||||
hmr: {
|
||||
protocol: ctx.nuxt.options.devServer.https ? 'wss' : 'ws',
|
||||
port: hmrPort,
|
||||
},
|
||||
})
|
||||
}
|
||||
if (typeof clientConfig.server.hmr !== 'object' || !clientConfig.server.hmr.server) {
|
||||
const hmrPortDefault = 24678 // Vite's default HMR port
|
||||
serverDefaults.hmr!.port = await getPort({
|
||||
port: hmrPortDefault,
|
||||
ports: Array.from({ length: 20 }, (_, i) => hmrPortDefault + 1 + i),
|
||||
})
|
||||
}
|
||||
if (ctx.nuxt.options.devServer.https) {
|
||||
serverDefaults.https = ctx.nuxt.options.devServer.https === true ? {} : ctx.nuxt.options.devServer.https
|
||||
}
|
||||
clientConfig.server = defu(clientConfig.server, serverDefaults as ViteConfig['server'])
|
||||
}
|
||||
|
||||
// Add analyze plugin if needed
|
||||
|
Loading…
Reference in New Issue
Block a user