From c30793c82e2124bd656adecdad3a69156f4bcc5d Mon Sep 17 00:00:00 2001 From: yoho Date: Fri, 29 Apr 2022 08:23:42 +0800 Subject: [PATCH] perf: promise.all --- .../src/node/server/middlewares/indexHtml.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/vite/src/node/server/middlewares/indexHtml.ts b/packages/vite/src/node/server/middlewares/indexHtml.ts index 4743516bfeaa68..8638492b1c2001 100644 --- a/packages/vite/src/node/server/middlewares/indexHtml.ts +++ b/packages/vite/src/node/server/middlewares/indexHtml.ts @@ -188,17 +188,18 @@ const devHtmlHook: IndexHtmlTransformHook = async ( } }) - for (let index = 0; index < styleUrl.length; index++) { - const { start, end, code } = styleUrl[index] - const url = filename + `?html-proxy&${index}.css` + await Promise.all( + styleUrl.map(async ({ start, end, code }, index) => { + const url = filename + `?html-proxy&${index}.css` - // ensure module in graph after successful load - const mod = await moduleGraph.ensureEntryFromUrl(url, false) - ensureWatchedFile(watcher, mod.file, config.root) + // ensure module in graph after successful load + const mod = await moduleGraph.ensureEntryFromUrl(url, false) + ensureWatchedFile(watcher, mod.file, config.root) - const result = await server!.pluginContainer.transform(code, url) - s.overwrite(start, end, result?.code || '') - } + const result = await server!.pluginContainer.transform(code, url) + s.overwrite(start, end, result?.code || '') + }) + ) html = s.toString()