]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
ui: fix VITE_PUBLIC_SERVER variable reading (#24845)
authorIlya <redacted>
Thu, 13 Aug 2026 17:31:51 +0000 (20:31 +0300)
committerGitHub <redacted>
Thu, 13 Aug 2026 17:31:51 +0000 (19:31 +0200)
tools/ui/vite.config.ts

index f650b4cfb96a98c8e0ce3ca4cd4e6e8c373db338..0f24a600bff77dc8120f82682342ba5461e98d59 100644 (file)
@@ -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()
-       ],
+       return {
+               build: {
+                       assetsInlineLimit: 32000,
+                       chunkSizeWarningLimit: 3072,
+                       minify: true
+               },
 
-       resolve: {
-               alias: {
-                       'katex-fonts': resolve('node_modules/katex/dist/fonts')
-               }
-       },
+               plugins: [
+                       tailwindcss(),
+                       sveltekit(),
+                       SvelteKitPWA(SVELTEKIT_PWA_OPTIONS),
+                       splashScreenPlugin(),
+                       buildInfoPlugin(),
+                       nerdamerPlugin(),
+                       relativizeBasePlugin()
+               ],
 
-       server: {
-               fs: {
-                       allow: [searchForWorkspaceRoot(process.cwd()), resolve(__dirname, 'tests')]
-               },
-               headers: {
-                       'Cross-Origin-Embedder-Policy': 'require-corp',
-                       'Cross-Origin-Opener-Policy': 'same-origin'
+               resolve: {
+                       alias: {
+                               'katex-fonts': resolve('node_modules/katex/dist/fonts')
+                       }
                },
-               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']
-                               }
+               server: {
+                       fs: {
+                               allow: [searchForWorkspaceRoot(process.cwd()), resolve(__dirname, 'tests')]
                        },
-
-                       {
-                               extends: './vite.config.ts',
-                               test: {
-                                       environment: 'node',
-                                       include: ['tests/unit/**/*.{test,spec}.{js,ts}'],
-                                       name: 'unit'
-                               }
+                       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',
-                               plugins: [
-                                       storybookTest({
-                                               storybookScript: 'pnpm run storybook --no-open'
-                                       })
-                               ],
-                               test: {
-                                       browser: { ...browserBaseConfig, instances: [{ browser: 'chromium', headless: true }] },
-                                       name: 'ui'
+                               {
+                                       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'
+                                       }
                                }
-                       }
-               ]
-       }
+                       ]
+               }
+       };
 });