vehicle-monitor/build/server.ts

34 lines
918 B
TypeScript
Raw Normal View History

2025-02-26 16:31:59 +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);
const options: ServerOptions = {
strictPort: VITE_STRICT_PORT,
port: VITE_PORT,
2025-02-26 16:31:59 +08:00
host: '0.0.0.0',
2025-02-25 23:14:50 +08:00
open: true,
cors: true,
proxy: {
2025-02-26 16:31:59 +08:00
'/api': {
2025-02-25 23:14:50 +08:00
target: VITE_APP_URL,
changeOrigin: true,
2025-02-26 16:31:59 +08:00
rewrite: (path: string) => path.replace(/^\/admin/, '/api'),
2025-02-25 23:14:50 +08:00
},
2025-02-26 16:31:59 +08:00
'/mock': {
2025-02-25 23:14:50 +08:00
target: VITE_APP_URL,
changeOrigin: true,
2025-02-26 16:31:59 +08:00
rewrite: (path: string) => path.replace(/^\/mock/, '/mock'),
2025-02-25 23:14:50 +08:00
},
},
// 预热文件以提前转换和缓存结果,降低启动期间的初始页面加载时长并防止转换瀑布
warmup: {
2025-02-26 16:31:59 +08:00
clientFiles: ['./index.html', './src/{views,components}/*'],
2025-02-25 23:14:50 +08:00
},
};
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
};