vite.config.js 671 B

12345678910111213141516171819202122232425
  1. import { defineConfig, loadEnv } from 'vite'
  2. import react from '@vitejs/plugin-react'
  3. // https://vite.dev/config/
  4. export default defineConfig(({ mode }) => {
  5. const env = loadEnv(mode, process.cwd(), '')
  6. return {
  7. plugins: [react()],
  8. server: {
  9. proxy: {
  10. // 开发环境下把 /api 同源代理到后端,避免浏览器 CORS 预检
  11. '/api': {
  12. target: env.VITE_DEV_API_TARGET || 'http://127.0.0.1:3000',
  13. changeOrigin: true,
  14. },
  15. },
  16. },
  17. test: {
  18. environment: 'jsdom',
  19. setupFiles: './src/test/setup.ts',
  20. exclude: ['**/.worktrees/**', '**/node_modules/**', '**/dist/**'],
  21. },
  22. }
  23. })