mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
feat(vite): log vite-node hmr updates (#6351)
This commit is contained in:
parent
2abf4a5bc1
commit
23329e0599
@ -1,5 +1,7 @@
|
||||
import { performance } from 'node:perf_hooks'
|
||||
import { ViteNodeRunner } from 'vite-node/client'
|
||||
import { $fetch } from 'ohmyfetch'
|
||||
import consola from 'consola'
|
||||
import { getViteNodeOptions } from './vite-node-shared.mjs'
|
||||
|
||||
const viteNodeOptions = getViteNodeOptions()
|
||||
@ -25,12 +27,21 @@ export default async (ssrContext) => {
|
||||
const invalidates = await $fetch('/invalidates', {
|
||||
baseURL: viteNodeOptions.baseURL
|
||||
})
|
||||
const updates = new Set()
|
||||
for (const key of invalidates) {
|
||||
runner.moduleCache.delete(key)
|
||||
if (runner.moduleCache.delete(key)) {
|
||||
updates.add(key)
|
||||
}
|
||||
}
|
||||
|
||||
// Execute SSR bundle on demand
|
||||
const start = performance.now()
|
||||
render = render || (await runner.executeFile(viteNodeOptions.entryPath)).default
|
||||
if (updates.size) {
|
||||
const time = Math.round((performance.now() - start) * 1000) / 1000
|
||||
consola.success(`Vite server hmr ${updates.size} files`, time ? `in ${time}ms` : '')
|
||||
}
|
||||
|
||||
const result = await render(ssrContext)
|
||||
return result
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user