This repository has been archived on 2026-09-13. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
BPOS-TMP-REPO/apps/web/vite.config.ts
T

42 lines
1.6 KiB
TypeScript

import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { fileURLToPath } from 'node:url';
const root = fileURLToPath(new URL('../..', import.meta.url));
const p = (rel: string) => fileURLToPath(new URL(rel, import.meta.url));
export default defineConfig({
plugins: [react()],
resolve: {
alias: {
'@contracts': `${root}packages/contracts/src/index.ts`,
'@sfeel': `${root}packages/sfeel/src/index.ts`,
'@ui': `${root}packages/ui-kit/src/index.ts`,
'@utils': `${root}packages/utils/src/index.ts`,
'@features': p('./src/features'),
'@web-shared': p('./src/shared'),
'@contracts/': `${root}packages/contracts/src/`,
},
},
server: {
port: 5173,
/*
* 双栈全绑(host: true = `::` 双栈 any)。
*
* 这坑栽过**两次**:不给 host 时只绑 `[::1]`,`127.0.0.1` 连不上;
* 改绑 `127.0.0.1` 后 `[::1]` 又连不上 —— 单栈回环怎么绑都有一族是死的,
* 浏览器把 localhost 解析到哪族全看系统心情,表现就是「时好时坏」。
* 回环双栈没有单 socket 的绑法,只能 any。
*
* 代价说明白:这会暴露到局域网 —— 但 API 从来就是 `*:8787`(Node 默认双栈 any),
* Web 跟它对齐并没有扩大暴露面;有登录门,且这是开发机。
* 要收回环,把这里改回 '127.0.0.1',并接受 [::1] 那族不通。
*/
host: true,
proxy: {
// 默认连测试服务器;本地起 API 时用 API_PROXY_TARGET=http://127.0.0.1:8787 覆盖
'/api': { target: process.env.API_PROXY_TARGET ?? 'http://150.158.83.131:46100', changeOrigin: true },
},
},
});