From 88a9c55604e198905eaca4db4fb7d2541d908c53 Mon Sep 17 00:00:00 2001 From: Lukas Waslowski Date: Tue, 3 Dec 2024 12:03:20 +0000 Subject: [PATCH] ViteBuilder: Allow viteFinal to modify the configuration before getOptimizeDeps triggers resolveConfig --- code/builders/builder-vite/src/vite-server.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/code/builders/builder-vite/src/vite-server.ts b/code/builders/builder-vite/src/vite-server.ts index ff235aa93833..45456c994f90 100644 --- a/code/builders/builder-vite/src/vite-server.ts +++ b/code/builders/builder-vite/src/vite-server.ts @@ -28,11 +28,19 @@ export async function createViteServer(options: Options, devServer: Server) { }, }, appType: 'custom' as const, - optimizeDeps: await getOptimizeDeps(commonCfg, options), }; const finalConfig = await presets.apply('viteFinal', config, options); + // getOptimizeDeps calls resolveConfig internally, and should therefore + // be invoked on the fully finalized configuration, in case viteFinal + // has applied some changes that were necessary for the configuration + // to be valid. + const finalConfigWithDeps = { + ...finalConfig, + optimizeDeps: await getOptimizeDeps(finalConfig, options), + }; + const { createServer } = await import('vite'); - return createServer(await sanitizeEnvVars(options, finalConfig)); + return createServer(await sanitizeEnvVars(options, finalConfigWithDeps)); }