refactor: 简化项目配置,改用环境变量端口并专注 MSI 发布

- 重命名项目为 openbridgeTokenUsageViewer (camelCase 风格)
- 移除 DJB2 hash 端口计算,改用 PROJECT_SERVER_PORT 环境变量 (默认 3000)
- 删除 src/lib/project-port.ts 冗余模块
- 打包目标从 "all" 改为 "msi",专注 Windows 安装程序发布
This commit is contained in:
2026-01-22 14:19:43 +08:00
parent b520cdaf35
commit fa625ca301
11 changed files with 39 additions and 117 deletions

View File

@@ -7,37 +7,25 @@
* - Bun 运行时优化 (nitro preset: 'bun')
* - 静态资源内联 (serveStatic: 'inline')
* - React Compiler 自动优化 (无需手动 memo)
* - 基于项目名称的稳定端口 (使用 DJB2 hash)
* - 端口从环境变量 PROJECT_SERVER_PORT 读取 (默认 3000)
*/
import tailwindcss from '@tailwindcss/vite'
import { devtools as tanstackDevtools } from '@tanstack/devtools-vite'
import { tanstackStart } from '@tanstack/react-start/plugin/vite'
import react from '@vitejs/plugin-react'
import { nitro } from 'nitro/vite'
import { defineConfig } from 'vite'
import { defineConfig, loadEnv } from 'vite'
import tsconfigPaths from 'vite-tsconfig-paths'
// ============================================================================
// 项目配置 (集中管理)
// ============================================================================
/** 项目名称 - 用于生成稳定端口和 sidecar 命名 */
export const PROJECT_NAME = 'openbridge-token-usage-viewer'
/** 加载 .env 文件中的环境变量 */
const envVars = loadEnv('development', process.cwd(), '')
/**
* DJB2 Hash 算法 - 将项目名称转换为稳定端口
* 端口范围: 10000-60000
*/
const djb2Hash = (str: string): number => {
let hash = 5381
for (let i = 0; i < str.length; i++) {
hash = ((hash << 5) + hash + str.charCodeAt(i)) >>> 0
}
return hash
}
/** 开发服务器端口 (基于项目名称的稳定值) */
export const DEV_PORT = 10000 + (djb2Hash(PROJECT_NAME) % 50000)
/** 开发服务器端口 (从环境变量读取,默认 3000) */
const DEV_PORT = Number(envVars.PROJECT_SERVER_PORT) || 3000
export default defineConfig({
// 禁止清屏,方便与 Tauri 开发工具共用终端