Skip to content

Commit

Permalink
perf: promise.all
Browse files Browse the repository at this point in the history
  • Loading branch information
poyoho committed Apr 29, 2022
1 parent a5e7855 commit c30793c
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions packages/vite/src/node/server/middlewares/indexHtml.ts
Expand Up @@ -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()

Expand Down

0 comments on commit c30793c

Please sign in to comment.