28 lines
809 B
TypeScript
28 lines
809 B
TypeScript
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
|
||
}
|
||
}
|
||
}
|
||
};
|
||
});
|