mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
fix(vite): hmr port priority (#3190)
This commit is contained in:
parent
408a944ffd
commit
61188e15cf
@ -6,7 +6,6 @@ import viteJsxPlugin from '@vitejs/plugin-vue-jsx'
|
||||
import type { Connect } from 'vite'
|
||||
|
||||
import { joinURL } from 'ufo'
|
||||
import { getPort } from 'get-port-please'
|
||||
import { cacheDirPlugin } from './plugins/cache-dir'
|
||||
import { analyzePlugin } from './plugins/analyze'
|
||||
import { wpfs } from './utils/wpfs'
|
||||
@ -16,13 +15,6 @@ import { devStyleSSRPlugin } from './plugins/dev-ssr-css'
|
||||
import { DynamicBasePlugin, RelativeAssetPlugin } from './plugins/dynamic-base'
|
||||
|
||||
export async function buildClient (ctx: ViteBuildContext) {
|
||||
// TODO: After nitropack refactor, try if we can resuse the same server port as Nuxt
|
||||
const hmrPortDefault = 24678 // Vite's default HMR port
|
||||
const hmrPort = await getPort({
|
||||
port: hmrPortDefault,
|
||||
ports: Array.from({ length: 20 }, (_, i) => hmrPortDefault + 1 + i)
|
||||
})
|
||||
|
||||
const clientConfig: vite.InlineConfig = vite.mergeConfig(ctx.config, {
|
||||
define: {
|
||||
'process.server': false,
|
||||
@ -56,11 +48,7 @@ export async function buildClient (ctx: ViteBuildContext) {
|
||||
})
|
||||
],
|
||||
server: {
|
||||
middlewareMode: true,
|
||||
hmr: {
|
||||
port: hmrPort,
|
||||
clientPort: hmrPort
|
||||
}
|
||||
middlewareMode: true
|
||||
}
|
||||
} as ViteOptions)
|
||||
|
||||
|
@ -6,6 +6,7 @@ import type { InlineConfig, SSROptions } from 'vite'
|
||||
import type { Options } from '@vitejs/plugin-vue'
|
||||
import { sanitizeFilePath } from 'mlly'
|
||||
import { joinURL, withoutLeadingSlash } from 'ufo'
|
||||
import { getPort } from 'get-port-please'
|
||||
import { buildClient } from './client'
|
||||
import { buildServer } from './server'
|
||||
import virtual from './plugins/virtual'
|
||||
@ -23,6 +24,13 @@ export interface ViteBuildContext {
|
||||
}
|
||||
|
||||
export async function bundle (nuxt: Nuxt) {
|
||||
// TODO: After nitropack refactor, try if we can resuse the same server port as Nuxt
|
||||
const hmrPortDefault = 24678 // Vite's default HMR port
|
||||
const hmrPort = await getPort({
|
||||
port: hmrPortDefault,
|
||||
ports: Array.from({ length: 20 }, (_, i) => hmrPortDefault + 1 + i)
|
||||
})
|
||||
|
||||
const ctx: ViteBuildContext = {
|
||||
nuxt,
|
||||
config: vite.mergeConfig(
|
||||
@ -85,6 +93,10 @@ export async function bundle (nuxt: Nuxt) {
|
||||
virtual(nuxt.vfs)
|
||||
],
|
||||
server: {
|
||||
hmr: {
|
||||
clientPort: hmrPort,
|
||||
port: hmrPort
|
||||
},
|
||||
fs: {
|
||||
strict: false,
|
||||
allow: [
|
||||
|
Loading…
Reference in New Issue
Block a user