1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| import { defineConfig, type UserConfig } from 'vite'; import viteConfig from './vite.config';
export default defineConfig(({ mode }) => { let proxy: Required<UserConfig>['server']['proxy'] = undefined; if (mode === 'proxy-dev') { proxy = proxyConfig['dev']; } else if (mode === 'proxy-qa') { proxy = proxyConfig['qa']; } else if (mode === 'proxy-prep') { proxy = proxyConfig['prep']; } else { proxy = undefined; }
const draft = { ...viteConfig, server: { ...viteConfig['server'], proxy, }, }; return draft; });
const proxyConfig: { [key in 'dev' | 'qa' | 'prep']?: Required<UserConfig>['server']['proxy'] } = { dev: { '/PROXY_DOMAIN': { target: 'https://devapi.domain.com', changeOrigin: true, rewrite: path => path.replace(/^\/PROXY_AAA/, ''), }, }, qa: { '/PROXY_DOMAIN': { target: 'https://qaapi.domain.com', changeOrigin: true, rewrite: path => path.replace(/^\/PROXY_DOMAIN/, ''), }, }, prep: { '/PROXY_DOMAIN': { target: 'https://prepapi.domain.com', changeOrigin: true, rewrite: path => path.replace(/^\/PROXY_DOMAIN/, ''), }, }, };
|