From 644d120248bbde6ed594b798092a7b5f6d7e58c5 Mon Sep 17 00:00:00 2001 From: patak Date: Tue, 16 Jan 2024 05:29:57 +0100 Subject: [PATCH] perf: simplify isHtmlProxy regex (#15590) --- packages/vite/src/node/plugins/html.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/node/plugins/html.ts b/packages/vite/src/node/plugins/html.ts index b37d33e0b018ec..84461ba6907c1c 100644 --- a/packages/vite/src/node/plugins/html.ts +++ b/packages/vite/src/node/plugins/html.ts @@ -45,6 +45,8 @@ interface ScriptAssetsUrl { const htmlProxyRE = /\?html-proxy=?(?:&inline-css)?(?:&style-attr)?&index=(\d+)\.(js|css)$/ +const isHtmlProxyRE = /\?html-proxy\b/ + const inlineCSSRE = /__VITE_INLINE_CSS__([a-z\d]{8}_\d+)__/g // Do not allow preceding '.', but do allow preceding '...' for spread operations const inlineImportRE = @@ -63,7 +65,7 @@ const importMapAppendRE = new RegExp( 'i', ) -export const isHTMLProxy = (id: string): boolean => htmlProxyRE.test(id) +export const isHTMLProxy = (id: string): boolean => isHtmlProxyRE.test(id) export const isHTMLRequest = (request: string): boolean => htmlLangRE.test(request) @@ -88,7 +90,7 @@ export function htmlInlineProxyPlugin(config: ResolvedConfig): Plugin { name: 'vite:html-inline-proxy', resolveId(id) { - if (htmlProxyRE.test(id)) { + if (isHTMLProxy(id)) { return id } },