Skip to content

Commit

Permalink
perf: avoid new URL() in hot path
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev committed Mar 29, 2023
1 parent 9697e64 commit 0a09499
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/vite/src/node/server/moduleGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,11 @@ export class ModuleGraph {
!url.startsWith(`virtual:`)
) {
const ext = extname(cleanUrl(resolvedId))
const { pathname, search, hash } = new URL(url, 'relative://')
if (ext && !pathname!.endsWith(ext)) {
url = pathname + ext + search + hash
if (ext) {
const pathname = cleanUrl(url)
if (!pathname.endsWith(ext)) {
url = pathname + ext + url.slice(pathname.length)
}
}
}
return [url, resolvedId, resolved?.meta]
Expand Down

0 comments on commit 0a09499

Please sign in to comment.