|
@@ -1,22 +1,25 @@
|
|
|
-import { defineConfig } from 'vite'
|
|
|
|
|
|
|
+import { defineConfig, loadEnv } from 'vite'
|
|
|
import react from '@vitejs/plugin-react'
|
|
import react from '@vitejs/plugin-react'
|
|
|
|
|
|
|
|
// https://vite.dev/config/
|
|
// https://vite.dev/config/
|
|
|
-export default defineConfig({
|
|
|
|
|
- plugins: [react()],
|
|
|
|
|
- server: {
|
|
|
|
|
- proxy: {
|
|
|
|
|
- // 开发环境下把 /api 同源代理到后端,避免浏览器 CORS 预检
|
|
|
|
|
- // 可选:把 client.ts 的 API_BASE 设为相对 '/api/v1' 即走此同源代理
|
|
|
|
|
- '/api': {
|
|
|
|
|
- target: 'http://127.0.0.1:3000',
|
|
|
|
|
- changeOrigin: true,
|
|
|
|
|
|
|
+export default defineConfig(({ mode }) => {
|
|
|
|
|
+ const env = loadEnv(mode, process.cwd(), '')
|
|
|
|
|
+
|
|
|
|
|
+ return {
|
|
|
|
|
+ plugins: [react()],
|
|
|
|
|
+ server: {
|
|
|
|
|
+ proxy: {
|
|
|
|
|
+ // 开发环境下把 /api 同源代理到后端,避免浏览器 CORS 预检
|
|
|
|
|
+ '/api': {
|
|
|
|
|
+ target: env.VITE_DEV_API_TARGET || 'http://127.0.0.1:3000',
|
|
|
|
|
+ changeOrigin: true,
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- test: {
|
|
|
|
|
- environment: 'jsdom',
|
|
|
|
|
- setupFiles: './src/test/setup.ts',
|
|
|
|
|
- exclude: ['**/.worktrees/**', '**/node_modules/**', '**/dist/**'],
|
|
|
|
|
- },
|
|
|
|
|
|
|
+ test: {
|
|
|
|
|
+ environment: 'jsdom',
|
|
|
|
|
+ setupFiles: './src/test/setup.ts',
|
|
|
|
|
+ exclude: ['**/.worktrees/**', '**/node_modules/**', '**/dist/**'],
|
|
|
|
|
+ },
|
|
|
|
|
+ }
|
|
|
})
|
|
})
|