mirror of
https://ghfast.top/https://github.com/aeroxw/tick-stock-panel.git
synced 2026-09-12 14:24:15 +08:00
- 统一开发脚本、Vite 代理与 Docker Compose 的 HOST/PORT 配置
- 首次启动按字面值读取 AUTH_PASSWORD,避免 ${VAR} 被环境变量插值
- 已有 auth.json 时继续以 Web 端密码为准,不受 .env 覆盖
55 lines
2.0 KiB
JavaScript
55 lines
2.0 KiB
JavaScript
import { defineConfig } from 'vite';
|
|
import react from '@vitejs/plugin-react';
|
|
import path from 'node:path';
|
|
const backendHost = process.env.BACKEND_HOST || '127.0.0.1';
|
|
const proxyHost = ['0.0.0.0', '::'].includes(backendHost) ? '127.0.0.1' : backendHost;
|
|
const backendPort = process.env.BACKEND_PORT || '3018';
|
|
const backendTarget = `http://${proxyHost}:${backendPort}`;
|
|
export default defineConfig({
|
|
plugins: [react()],
|
|
resolve: {
|
|
alias: {
|
|
'@': path.resolve(__dirname, './src'),
|
|
},
|
|
},
|
|
server: {
|
|
host: '0.0.0.0', // dev.sh / dev.ps1 会用 CLI --host 覆盖
|
|
port: 3011,
|
|
proxy: {
|
|
// dev 时 /api 转发到与启动脚本相同的 FastAPI 地址
|
|
'/api': {
|
|
target: backendTarget,
|
|
// SSE 端点需要禁用缓冲
|
|
configure: (proxy) => {
|
|
proxy.on('proxyReq', (_proxyReq, req) => {
|
|
if (req.url?.includes('/stream')) {
|
|
_proxyReq.setHeader('Accept', 'text/event-stream');
|
|
_proxyReq.setHeader('Cache-Control', 'no-cache');
|
|
_proxyReq.setHeader('Connection', 'keep-alive');
|
|
}
|
|
});
|
|
},
|
|
},
|
|
'/health': backendTarget,
|
|
},
|
|
},
|
|
build: {
|
|
outDir: 'dist',
|
|
sourcemap: false,
|
|
rollupOptions: {
|
|
output: {
|
|
// 把重型图表库拆到独立 chunk, 避免打进主包 + 让页面按需加载。
|
|
// 用函数形式按 node_modules 路径匹配, 比对象形式更可靠。
|
|
manualChunks(id) {
|
|
if (id.includes('node_modules')) {
|
|
if (id.includes('echarts'))
|
|
return 'echarts';
|
|
if (id.includes('lightweight-charts'))
|
|
return 'lightweight-charts';
|
|
}
|
|
},
|
|
},
|
|
},
|
|
},
|
|
});
|