From 9c5531e2bf2c95e86eeac807d7109de29266ca7b Mon Sep 17 00:00:00 2001 From: Ilya Date: Thu, 13 Aug 2026 20:31:51 +0300 Subject: [PATCH] ui: fix VITE_PUBLIC_SERVER variable reading (#24845) --- tools/ui/vite.config.ts | 150 +++++++++++++++++++++------------------- 1 file changed, 77 insertions(+), 73 deletions(-) diff --git a/tools/ui/vite.config.ts b/tools/ui/vite.config.ts index f650b4cfb..0f24a600b 100644 --- a/tools/ui/vite.config.ts +++ b/tools/ui/vite.config.ts @@ -10,10 +10,9 @@ import { SvelteKitPWA } from '@vite-pwa/sveltekit'; import { playwright } from '@vitest/browser-playwright'; import { dirname, resolve } from 'path'; import { fileURLToPath } from 'url'; -import { defineConfig, searchForWorkspaceRoot } from 'vite'; +import { defineConfig, loadEnv, searchForWorkspaceRoot } from 'vite'; const __dirname = dirname(fileURLToPath(import.meta.url)); -const SERVER_ORIGIN = import.meta.env?.VITE_PUBLIC_SERVER_ORIGIN || 'http://localhost:8080'; // eslint-disable-next-line @typescript-eslint/no-explicit-any const browserBaseConfig: any = { enabled: true, @@ -25,80 +24,85 @@ const browserBaseConfig: any = { }) }; -export default defineConfig({ - build: { - assetsInlineLimit: 32000, - chunkSizeWarningLimit: 3072, - minify: true - }, +export default defineConfig(({ mode }) => { + const env = loadEnv(mode, process.cwd(), 'VITE_PUBLIC_'); + const SERVER_ORIGIN = env.VITE_PUBLIC_SERVER_ORIGIN || 'http://localhost:8080'; - plugins: [ - tailwindcss(), - sveltekit(), - SvelteKitPWA(SVELTEKIT_PWA_OPTIONS), - splashScreenPlugin(), - buildInfoPlugin(), - nerdamerPlugin(), - relativizeBasePlugin() - ], - - resolve: { - alias: { - 'katex-fonts': resolve('node_modules/katex/dist/fonts') - } - }, - - server: { - fs: { - allow: [searchForWorkspaceRoot(process.cwd()), resolve(__dirname, 'tests')] + return { + build: { + assetsInlineLimit: 32000, + chunkSizeWarningLimit: 3072, + minify: true }, - headers: { - 'Cross-Origin-Embedder-Policy': 'require-corp', - 'Cross-Origin-Opener-Policy': 'same-origin' - }, - proxy: { - '/cors-proxy': SERVER_ORIGIN, - '/models': SERVER_ORIGIN, - '/props': SERVER_ORIGIN, - '/slots': SERVER_ORIGIN, - '/tools': SERVER_ORIGIN, - '/v1': SERVER_ORIGIN - } - }, - test: { - projects: [ - { - extends: './vite.config.ts', - test: { - browser: browserBaseConfig, - include: ['tests/client/**/*.svelte.{test,spec}.{js,ts}'], - name: 'client', - setupFiles: ['./vitest-setup-client.ts'] - } - }, + plugins: [ + tailwindcss(), + sveltekit(), + SvelteKitPWA(SVELTEKIT_PWA_OPTIONS), + splashScreenPlugin(), + buildInfoPlugin(), + nerdamerPlugin(), + relativizeBasePlugin() + ], - { - extends: './vite.config.ts', - test: { - environment: 'node', - include: ['tests/unit/**/*.{test,spec}.{js,ts}'], - name: 'unit' - } - }, - - { - extends: './vite.config.ts', - plugins: [ - storybookTest({ - storybookScript: 'pnpm run storybook --no-open' - }) - ], - test: { - browser: { ...browserBaseConfig, instances: [{ browser: 'chromium', headless: true }] }, - name: 'ui' - } + resolve: { + alias: { + 'katex-fonts': resolve('node_modules/katex/dist/fonts') } - ] - } + }, + + server: { + fs: { + allow: [searchForWorkspaceRoot(process.cwd()), resolve(__dirname, 'tests')] + }, + headers: { + 'Cross-Origin-Embedder-Policy': 'require-corp', + 'Cross-Origin-Opener-Policy': 'same-origin' + }, + proxy: { + '/cors-proxy': SERVER_ORIGIN, + '/models': SERVER_ORIGIN, + '/props': SERVER_ORIGIN, + '/slots': SERVER_ORIGIN, + '/tools': SERVER_ORIGIN, + '/v1': SERVER_ORIGIN + } + }, + + test: { + projects: [ + { + extends: './vite.config.ts', + test: { + browser: browserBaseConfig, + include: ['tests/client/**/*.svelte.{test,spec}.{js,ts}'], + name: 'client', + setupFiles: ['./vitest-setup-client.ts'] + } + }, + + { + extends: './vite.config.ts', + test: { + environment: 'node', + include: ['tests/unit/**/*.{test,spec}.{js,ts}'], + name: 'unit' + } + }, + + { + extends: './vite.config.ts', + plugins: [ + storybookTest({ + storybookScript: 'pnpm run storybook --no-open' + }) + ], + test: { + browser: { ...browserBaseConfig, instances: [{ browser: 'chromium', headless: true }] }, + name: 'ui' + } + } + ] + } + }; });