From 8c5674e10deb67aaf23b74fddedb5ff750ba3bb7 Mon Sep 17 00:00:00 2001 From: patak-dev Date: Mon, 20 May 2024 15:05:47 +0200 Subject: [PATCH] chore: respect ssr flag in clientInjectsions transform --- packages/vite/src/node/plugins/clientInjections.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/node/plugins/clientInjections.ts b/packages/vite/src/node/plugins/clientInjections.ts index b874b27d9944dd..f624b4091608f1 100644 --- a/packages/vite/src/node/plugins/clientInjections.ts +++ b/packages/vite/src/node/plugins/clientInjections.ts @@ -89,10 +89,11 @@ export function clientInjectionsPlugin(config: ResolvedConfig): Plugin { .replace(`__HMR_CONFIG_NAME__`, hmrConfigNameReplacement) } }, - async transform(code, id) { + async transform(code, id, options) { if (!this.environment) return // TODO: !environment.options.nodeCompatible ? - const ssr = this.environment.name !== 'client' + // TODO: Remove options?.ssr, Vitest currently hijacks this plugin + const ssr = options?.ssr ?? this.environment.name !== 'client' if (id === normalizedClientEntry || id === normalizedEnvEntry) { return injectConfigValues(code) } else if (!ssr && code.includes('process.env.NODE_ENV')) {