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
| import { fileURLToPath, URL } from 'node:url';
| import react from '@vitejs/plugin-react';
| import { defineConfig, loadEnv } from 'vite';
|
| /** 开发环境通过 Vite 代理访问后端,避免浏览器跨域。 */
| export default defineConfig(({ mode }) => {
| const env = loadEnv(mode, process.cwd(), '');
| const proxyTarget =
| env.VITE_API_PROXY_TARGET || env.VITE_API_BASE_URL || 'http://localhost:9090';
|
| return {
| plugins: [react()],
| resolve: {
| alias: {
| '@': fileURLToPath(new URL('./src', import.meta.url)),
| },
| },
| server: {
| port: 5173,
| host: true,
| proxy: {
| '/proxy-api': {
| target: proxyTarget,
| changeOrigin: true,
| rewrite: (path) => path.replace(/^\/proxy-api/, ''),
| },
| },
| },
| };
| });
|
|