mirror of
https://github.com/nuxt/nuxt.git
synced 2025-03-09 03:03:18 +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 type { Connect } from 'vite'
|
||||||
|
|
||||||
import { joinURL } from 'ufo'
|
import { joinURL } from 'ufo'
|
||||||
import { getPort } from 'get-port-please'
|
|
||||||
import { cacheDirPlugin } from './plugins/cache-dir'
|
import { cacheDirPlugin } from './plugins/cache-dir'
|
||||||
import { analyzePlugin } from './plugins/analyze'
|
import { analyzePlugin } from './plugins/analyze'
|
||||||
import { wpfs } from './utils/wpfs'
|
import { wpfs } from './utils/wpfs'
|
||||||
@ -16,13 +15,6 @@ import { devStyleSSRPlugin } from './plugins/dev-ssr-css'
|
|||||||
import { DynamicBasePlugin, RelativeAssetPlugin } from './plugins/dynamic-base'
|
import { DynamicBasePlugin, RelativeAssetPlugin } from './plugins/dynamic-base'
|
||||||
|
|
||||||
export async function buildClient (ctx: ViteBuildContext) {
|
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, {
|
const clientConfig: vite.InlineConfig = vite.mergeConfig(ctx.config, {
|
||||||
define: {
|
define: {
|
||||||
'process.server': false,
|
'process.server': false,
|
||||||
@ -56,11 +48,7 @@ export async function buildClient (ctx: ViteBuildContext) {
|
|||||||
})
|
})
|
||||||
],
|
],
|
||||||
server: {
|
server: {
|
||||||
middlewareMode: true,
|
middlewareMode: true
|
||||||
hmr: {
|
|
||||||
port: hmrPort,
|
|
||||||
clientPort: hmrPort
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} as ViteOptions)
|
} as ViteOptions)
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import type { InlineConfig, SSROptions } from 'vite'
|
|||||||
import type { Options } from '@vitejs/plugin-vue'
|
import type { Options } from '@vitejs/plugin-vue'
|
||||||
import { sanitizeFilePath } from 'mlly'
|
import { sanitizeFilePath } from 'mlly'
|
||||||
import { joinURL, withoutLeadingSlash } from 'ufo'
|
import { joinURL, withoutLeadingSlash } from 'ufo'
|
||||||
|
import { getPort } from 'get-port-please'
|
||||||
import { buildClient } from './client'
|
import { buildClient } from './client'
|
||||||
import { buildServer } from './server'
|
import { buildServer } from './server'
|
||||||
import virtual from './plugins/virtual'
|
import virtual from './plugins/virtual'
|
||||||
@ -23,6 +24,13 @@ export interface ViteBuildContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function bundle (nuxt: Nuxt) {
|
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 = {
|
const ctx: ViteBuildContext = {
|
||||||
nuxt,
|
nuxt,
|
||||||
config: vite.mergeConfig(
|
config: vite.mergeConfig(
|
||||||
@ -85,6 +93,10 @@ export async function bundle (nuxt: Nuxt) {
|
|||||||
virtual(nuxt.vfs)
|
virtual(nuxt.vfs)
|
||||||
],
|
],
|
||||||
server: {
|
server: {
|
||||||
|
hmr: {
|
||||||
|
clientPort: hmrPort,
|
||||||
|
port: hmrPort
|
||||||
|
},
|
||||||
fs: {
|
fs: {
|
||||||
strict: false,
|
strict: false,
|
||||||
allow: [
|
allow: [
|
||||||
|
Loading…
Reference in New Issue
Block a user