import { defineConfig, loadEnv } from 'vite'; import react from '@vitejs/plugin-react'; function normalizeBasePath(value: string | undefined) { const raw = value?.trim(); if (!raw || raw === '/') return '/'; if (raw === './') return './'; if (/^https?:\/\//.test(raw)) { return raw.endsWith('/') ? raw : `${raw}/`; } return `/${raw.replace(/^\/+|\/+$/g, '')}/`; } export default defineConfig(({ mode }) => { const env = loadEnv(mode, process.cwd(), ''); return { base: normalizeBasePath(env.VITE_BASE_PATH), plugins: [react()], }; });