From ec32cf9fc5e1e37d0e31dcd23cf62c39ac17d7d1 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Wed, 6 Apr 2022 13:54:53 +0800 Subject: [PATCH] fix(vite): improve warmup (#4106) --- packages/vite/src/utils/warmup.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/vite/src/utils/warmup.ts b/packages/vite/src/utils/warmup.ts index cda761e6e0..6fd4bf7991 100644 --- a/packages/vite/src/utils/warmup.ts +++ b/packages/vite/src/utils/warmup.ts @@ -1,19 +1,25 @@ import { logger } from '@nuxt/kit' 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() const warmup = async (url: string) => { - if (warmedUrls.has(url)) { return undefined } + if (warmedUrls.has(url)) { + return + } warmedUrls.add(url) try { await server.transformRequest(url) } catch (e) { logger.debug('Warmup for %s failed with: %s', url, e) } - const deps = Array.from(server.moduleGraph.urlToModuleMap.get(url)?.importedModules || []) - await Promise.all(deps.map(m => warmup(m.url))) + const mod = await server.moduleGraph.getModuleByUrl(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)))