mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-19 01:45:53 +00:00
fix(vite): improve warmup (#4106)
This commit is contained in:
parent
4ba0604522
commit
ec32cf9fc5
@ -1,19 +1,25 @@
|
|||||||
import { logger } from '@nuxt/kit'
|
import { logger } from '@nuxt/kit'
|
||||||
import type { ViteDevServer } from 'vite'
|
import type { ViteDevServer } from 'vite'
|
||||||
|
|
||||||
export async function warmupViteServer (server: ViteDevServer, entries: string[]) {
|
export async function warmupViteServer (
|
||||||
|
server: ViteDevServer,
|
||||||
|
entries: string[]
|
||||||
|
) {
|
||||||
const warmedUrls = new Set<String>()
|
const warmedUrls = new Set<String>()
|
||||||
|
|
||||||
const warmup = async (url: string) => {
|
const warmup = async (url: string) => {
|
||||||
if (warmedUrls.has(url)) { return undefined }
|
if (warmedUrls.has(url)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
warmedUrls.add(url)
|
warmedUrls.add(url)
|
||||||
try {
|
try {
|
||||||
await server.transformRequest(url)
|
await server.transformRequest(url)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.debug('Warmup for %s failed with: %s', url, e)
|
logger.debug('Warmup for %s failed with: %s', url, e)
|
||||||
}
|
}
|
||||||
const deps = Array.from(server.moduleGraph.urlToModuleMap.get(url)?.importedModules || [])
|
const mod = await server.moduleGraph.getModuleByUrl(url)
|
||||||
await Promise.all(deps.map(m => warmup(m.url)))
|
const deps = Array.from(mod?.importedModules || [])
|
||||||
|
await Promise.all(deps.map(m => warmup(m.url.replace('/@id/__x00__', '\0'))))
|
||||||
}
|
}
|
||||||
|
|
||||||
await Promise.all(entries.map(entry => warmup(entry)))
|
await Promise.all(entries.map(entry => warmup(entry)))
|
||||||
|
Loading…
Reference in New Issue
Block a user