import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' import path from "path" import tailwindcss from "@tailwindcss/vite" // https://vite.dev/config/ export default defineConfig({ server: { proxy: { // 1. 匹配所有以 /api 开头的请求 '/api': { target: 'http://localhost', // 你的 Java 后端地址 changeOrigin: true, // 允许跨域 // 2. 路径重写:如果后端接口没有 /api 前缀,就把它删掉 rewrite: (path) => path.replace(/^\/api/, '') }, } }, plugins: [ tailwindcss(), react({ babel: { plugins: [['babel-plugin-react-compiler']], }, }), ], resolve: { alias: { "@": path.resolve(__dirname, "./src"), }, }, })