Skip to content

Commit

Permalink
feat(dev): reuse main dev port for vite hmr (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Sep 14, 2023
1 parent 5e97bc2 commit 61383d1
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/utils/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,28 @@ class NuxtDevServer extends EventEmitter {
},
})

// Connect Vite HMR
this._currentNuxt.hooks.hookOnce(
'vite:extendConfig',
(config, { isClient }) => {
if (isClient && config.server) {
config.server.hmr = {
...(config.server.hmr as Exclude<
typeof config.server.hmr,
boolean
>),
protocol: undefined,
port: undefined,
host: undefined,
server: this.listener.server,
}
}
},
)
this._currentNuxt.hooks.hookOnce('close', () => {
this.listener.server.removeAllListeners('upgrade')
})

// Write manifest and also check if we need cache invalidation
if (!reload) {
const previousManifest = await loadNuxtManifest(
Expand Down

0 comments on commit 61383d1

Please sign in to comment.