Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(lib): improve helper inject regex #8741

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/vite/src/node/plugins/esbuild.ts
Expand Up @@ -27,9 +27,9 @@ import { searchForWorkspaceRoot } from '..'
const debug = createDebugger('vite:esbuild')

const INJECT_HELPERS_IIFE_RE =
/(.*)((?:const|var) [^\s]+=function\([^)]*?\){"use strict";)(.*)/s
/^(.*)((?:const|var) [^\s]+=function\([^)]*?\){"use strict";)/s
const INJECT_HELPERS_UMD_RE =
/(.*)(\(function\([^)]*?\){.+amd.+function\([^)]*?\){"use strict";)(.*)/s
/^(.*)(\(function\([^)]*?\){.+amd.+function\([^)]*?\){"use strict";)/s

let server: ViteDevServer

Expand Down Expand Up @@ -273,7 +273,7 @@ export const buildEsbuildPlugin = (config: ResolvedConfig): Plugin => {
if (injectHelpers) {
res.code = res.code.replace(
injectHelpers,
(_, helpers, header, rest) => header + helpers + rest
(_, helpers, header) => header + helpers
)
}
}
Expand Down