packServer/frontend/vite.config.ts

43 lines
1.6 KiB
TypeScript
Raw 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 { fileURLToPath, URL } from 'node:url';
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
/**
* ⚠️ 端口约定(本机同时跑很多项目,**不要用 Vite 默认的 5173**,很容易撞)
* - 前端 dev :7301(`VITE_PORT` 可覆盖)
* - 前端 preview:7302(预览 dist 构建产物)
* - 后端 dev :7300(后端默认端口,`VITE_BACKEND` 可覆盖)
* - 前端 preview:7302(预览 dist 构建产物)
* `strictPort: true` → 端口被占用时**直接报错**,不会悄悄换到 5174(否则和后端反代对不上)
* 开发时前端调接口走同源代理:/api、/health → 后端(`VITE_BACKEND` 可覆盖,默认 127.0.0.1:7300)
*/
const backend = process.env.VITE_BACKEND || 'http://127.0.0.1:7300';
export default defineConfig({
plugins: [vue()],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
},
server: {
host: '127.0.0.1',
port: Number(process.env.VITE_PORT || 7301),
strictPort: true,
// 前端只调接口:/api 与 /health 反代到 Egg(同源,没有跨域,也不用带 cookie)
// /download 是安装包与 version.json(浏览器取不着本机软件时给下载入口用)
proxy: {
'/api': { target: backend, changeOrigin: true },
'/health': { target: backend, changeOrigin: true },
'/download': { target: backend, changeOrigin: true },
},
},
preview: {
port: Number(process.env.VITE_PREVIEW_PORT || 7302),
strictPort: true,
},
build: {
outDir: 'dist',
},
});