You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
805 B
TypeScript
32 lines
805 B
TypeScript
11 months ago
|
import react from "@vitejs/plugin-react-swc";
|
||
|
import { fileURLToPath, URL } from "node:url";
|
||
|
import type { ConfigEnv } from "vite";
|
||
|
import { loadEnv } from "vite";
|
||
|
|
||
|
// https://vitejs.dev/config/
|
||
|
export default ({ command, mode }: ConfigEnv) => {
|
||
|
const root = process.cwd();
|
||
|
const env = loadEnv(mode, root);
|
||
|
const isBuild = command === "build"; // 可以根据开发 / 生产环境做区分
|
||
|
const proxyConfig = {
|
||
|
target: env.VITE_GLOB_APP_URL,
|
||
|
changeOrigin: true,
|
||
|
rewrite: (path: string) => path.replace(/^\/api/, ""),
|
||
|
};
|
||
|
return {
|
||
|
plugins: [react()],
|
||
|
resolve: {
|
||
|
alias: {
|
||
|
"@": fileURLToPath(new URL("./src", import.meta.url)),
|
||
|
},
|
||
|
},
|
||
|
server: {
|
||
|
proxy: {
|
||
|
"/api": proxyConfig,
|
||
|
},
|
||
|
open: true,
|
||
|
port: 5173,
|
||
|
},
|
||
|
};
|
||
|
};
|