fix: honor managed Vite profile environment
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { describe, it } from 'node:test';
|
||||
import { mergeViteEnv } from '../vite.config.ts';
|
||||
|
||||
void describe('game frontend Vite config', () => {
|
||||
void it('prefers managed runtime values over values loaded from env files', () => {
|
||||
const env = mergeViteEnv(
|
||||
{ VITE_APP_BASE_PATH: '/gateway', VITE_GAME_API_URL: '/gateway/api/trpc' },
|
||||
{ VITE_APP_BASE_PATH: '/hwe', VITE_GAME_API_URL: '/hwe/api/trpc' }
|
||||
);
|
||||
|
||||
assert.equal(env.VITE_APP_BASE_PATH, '/hwe');
|
||||
assert.equal(env.VITE_GAME_API_URL, '/hwe/api/trpc');
|
||||
});
|
||||
});
|
||||
@@ -23,9 +23,17 @@ const resolvePreviewAllowedHosts = (value: string | undefined): true | string[]
|
||||
return hosts;
|
||||
};
|
||||
|
||||
export const mergeViteEnv = (
|
||||
fileEnv: Record<string, string>,
|
||||
runtimeEnv: NodeJS.ProcessEnv
|
||||
): Record<string, string | undefined> => ({
|
||||
...fileEnv,
|
||||
...runtimeEnv,
|
||||
});
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig(({ mode }) => {
|
||||
const env = loadEnv(mode, process.cwd(), '');
|
||||
const env = mergeViteEnv(loadEnv(mode, process.cwd(), ''), process.env);
|
||||
return {
|
||||
base: normalizeBasePath(env.VITE_APP_BASE_PATH),
|
||||
plugins: [vue(), tailwindcss()],
|
||||
|
||||
Reference in New Issue
Block a user