Skip to content

Commit

Permalink
perf(define): don't compare id if no replacements needed
Browse files Browse the repository at this point in the history
  • Loading branch information
tony19 committed Sep 1, 2022
1 parent bce6fe2 commit b40fd91
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions packages/vite/src/node/plugins/define.ts
Expand Up @@ -110,6 +110,11 @@ export function definePlugin(config: ResolvedConfig): Plugin {
return
}

const [replacements, pattern] = ssr ? ssrPattern : defaultPattern
if (!pattern) {
return null
}

if (
// exclude html, css and static assets for performance
isHTMLRequest(id) ||
Expand All @@ -120,12 +125,6 @@ export function definePlugin(config: ResolvedConfig): Plugin {
return
}

const [replacements, pattern] = ssr ? ssrPattern : defaultPattern

if (!pattern) {
return null
}

const s = replaceInCode(code, pattern, replacements)
return s ? transformStableResult(s, id, config) : null
}
Expand Down

0 comments on commit b40fd91

Please sign in to comment.