- 添加 OpenBridge 四种主题切换 (day/bright/dusk/night) - 实现 DJB2 hash 算法生成项目专用端口 (14323) - 统一项目名称为 openbridge-token-usage-viewer - 更新 Tauri 应用名称、sidecar 命名和窗口标题 - 开发服务器端口从 3000 改为基于项目名称的稳定端口
89 lines
2.4 KiB
TypeScript
89 lines
2.4 KiB
TypeScript
/**
|
|
* Vite 构建配置
|
|
*
|
|
* 集成 TanStack Start (SSR) + Nitro (服务端) + Tailwind CSS + React Compiler。
|
|
*
|
|
* 特性:
|
|
* - Bun 运行时优化 (nitro preset: 'bun')
|
|
* - 静态资源内联 (serveStatic: 'inline')
|
|
* - React Compiler 自动优化 (无需手动 memo)
|
|
* - 基于项目名称的稳定端口 (使用 DJB2 hash)
|
|
*/
|
|
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 tsconfigPaths from 'vite-tsconfig-paths'
|
|
|
|
// ============================================================================
|
|
// 项目配置 (集中管理)
|
|
// ============================================================================
|
|
|
|
/** 项目名称 - 用于生成稳定端口和 sidecar 命名 */
|
|
export const PROJECT_NAME = 'openbridge-token-usage-viewer'
|
|
|
|
/**
|
|
* 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)
|
|
|
|
export default defineConfig({
|
|
// 禁止清屏,方便与 Tauri 开发工具共用终端
|
|
clearScreen: false,
|
|
|
|
build: {
|
|
// 使用 esbuild 进行 CSS 压缩
|
|
// 避免 lightningcss 处理第三方 CSS 时的兼容性问题
|
|
cssMinify: 'esbuild',
|
|
},
|
|
|
|
plugins: [
|
|
// TanStack 开发工具
|
|
tanstackDevtools(),
|
|
|
|
// Nitro 服务端框架 (Bun 运行时)
|
|
nitro({
|
|
preset: 'bun',
|
|
serveStatic: 'inline',
|
|
}),
|
|
|
|
// TypeScript 路径别名 (@/* -> src/*)
|
|
tsconfigPaths(),
|
|
|
|
// Tailwind CSS v4
|
|
tailwindcss(),
|
|
|
|
// TanStack Start SSR 框架
|
|
tanstackStart(),
|
|
|
|
// React + Babel (启用 React Compiler)
|
|
react({
|
|
babel: {
|
|
plugins: ['babel-plugin-react-compiler'],
|
|
},
|
|
}),
|
|
],
|
|
|
|
server: {
|
|
port: DEV_PORT,
|
|
// 如果端口被占用则报错,而不是自动切换端口
|
|
strictPort: false,
|
|
watch: {
|
|
// 忽略 Tauri 源码目录,避免不必要的重编译
|
|
ignored: ['**/src-tauri/**'],
|
|
},
|
|
},
|
|
})
|