Files
2026-10-09 00:16:37 -07:00

28 lines
809 B
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import react from "@vitejs/plugin-react";
import { fileURLToPath, URL } from "node:url";
import { defineConfig, loadEnv } from "vite";
// https://vite.dev/config/
export default defineConfig(({ mode }) => {
// 第三个参数传空字符串,读取所有环境变量(含不带 VITE_ 前缀的 DEV_PROXY_TARGET)
const env = loadEnv(mode, process.cwd(), "");
return {
plugins: [react()],
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url))
}
},
server: {
// 开发环境将 /api 代理到后端,避免跨域;后端接口需带 /api 前缀,否则在此配置 rewrite
proxy: {
"/api": {
target: env.DEV_PROXY_TARGET ?? "http://localhost:8080",
changeOrigin: true
}
}
}
};
});