vehicle-monitor/build/server.ts

34 lines
918 B
TypeScript
Raw Normal View History

2025-02-25 23:14:50 +08:00
import type { ServerOptions } from "vite";
import { wrapperEnv } from "./utils";
2025-02-24 18:23:33 +08:00
2025-02-24 22:45:14 +08:00
/* 开发服务配置 */
2025-02-25 23:14:50 +08:00
export const server = (mode) => {
const { VITE_PORT, VITE_APP_URL, VITE_STRICT_PORT } = wrapperEnv(mode);
2025-02-24 18:23:33 +08:00
2025-02-25 23:14:50 +08:00
const options: ServerOptions = {
strictPort: VITE_STRICT_PORT,
port: VITE_PORT,
host: "0.0.0.0",
open: true,
cors: true,
proxy: {
"/api": {
target: VITE_APP_URL,
changeOrigin: true,
rewrite: (path: string) => path.replace(/^\/admin/, "/api"),
},
"/mock": {
target: VITE_APP_URL,
changeOrigin: true,
rewrite: (path: string) => path.replace(/^\/mock/, "/mock"),
},
},
// 预热文件以提前转换和缓存结果,降低启动期间的初始页面加载时长并防止转换瀑布
warmup: {
clientFiles: ["./index.html", "./src/{views,components}/*"],
},
};
2025-02-24 18:23:33 +08:00
2025-02-25 23:14:50 +08:00
return options;
2025-02-24 18:23:33 +08:00
};