Files
ele-HeiXiu/vite.config.ts
YoungestSongMo 8b697e775d feat: 去除构建时版控变量 + 窗口标题动态版控 + 退出登录保留缓存 (0.0.24)
版控体系重构(13 文件):
- 移除 build.mjs --personal/--enterprise 参数和 EDITION 环境变量
- 统一安装包文件名:船长-HeiXiu-{os}-{版本号}-Setup.{ext}
- 简化 package.json 构建脚本,移除 :enterprise 变体
- scripts/*.mjs 不再接受 edition 参数
- 移除 shared/constants/app.ts 的 parseEdition()

窗口标题动态版控:
- 新格式:船长-HeiXiu-{os}-{版本号}(登录前)/ ·{版控} 后缀(登录后)
- 链路:AppProvider(account_type) → useEffect → appRuntime IPC → main process
- 移除 updater.ts 更新检查 API 的 edition 查询参数

本地存储生命周期修正:
- 退出登录不再自动清空缓存(user_id 隔离,重新登录命中缓存)
- clearUserStorage 添加 isOpen() 竞态守卫
- 移除 closeDatabase() 避免退出→重新登录后数据库不可用
- 手动「清理缓存」按钮保留

文档:
- CHANGELOG.md 新增 0.0.24 条目
- TODO.md 新增已完成项
2026-06-22 13:36:42 +08:00

107 lines
4.3 KiB
TypeScript
Raw Permalink 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 {defineConfig, loadEnv} from 'vite';
import path from 'node:path';
import electron from 'vite-plugin-electron/simple';
import react from '@vitejs/plugin-react';
import renderer from 'vite-plugin-electron-renderer';
import tailwindcss from '@tailwindcss/vite';
import {visualizer} from 'rollup-plugin-visualizer';
const __dirname = import.meta.dirname;
// ============================================================
// 热更新说明
// ============================================================
// 修改 src/ → React Fast Refresh组件级热替换不丢失状态
// 修改 electron/ → 主进程重建 + Electron 自动重启(预期行为)
// 修改 shared/ → 因为 shared/ 被主进程引用,也会触发重启
// 如需避免,可把仅渲染进程用的类型放到 src/types/
// ============================================================
export default defineConfig(({mode}) => {
// 加载 .env.development / .env.production 中的环境变量
const env = loadEnv(mode, __dirname, '');
return {
plugins: [
react(),
tailwindcss(),
electron({
main: {
// 主进程入口
entry: 'electron/main.ts',
// 只监听 electron/ 目录,避免 shared/ 变更误触重启
// (默认会监听 entry 文件的所有依赖,包括 shared/
},
preload: {
input: path.join(__dirname, 'electron/preload.ts'),
},
}),
renderer(),
// 打包体积分析(仅 ANALYZE=true 时生成 stats.html
process.env.ANALYZE &&
visualizer({
open: true,
gzipSize: true,
brotliSize: true,
filename: 'dist/stats.html',
}),
].filter(Boolean),
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
'@shared': path.resolve(__dirname, 'shared'),
},
},
// ============================================================
// 编译时注入环境变量到主进程
// 主进程中的 process.env.xxx 会在编译时被替换为实际值
// 这样无需在 OS 环境中设置这些变量
// ============================================================
define: {
'process.env.UPDATE_API_URL': JSON.stringify(env.UPDATE_API_URL || 'https://www.heixiu.com'),
},
// ============================================================
// 开发服务器 & HMR 配置
// ============================================================
server: {
port: 5173,
strictPort: true,
host: "0.0.0.0",
watch: {
// Windows 上默认的 fs.watch 有时不稳定,
// 如果文件保存后界面无反应,可临时开启 usePolling
// usePolling: true,
// interval: 100,
// 忽略不需要监听的目录,减少 CPU 占用
ignored: ['**/node_modules/**', '**/dist/**', '**/dist-electron/**', '**/release/**', '**/test-server/**', "**/**/*.md"],
},
// HMR 配置
hmr: {
// 在浏览器控制台显示 HMR 覆盖层(错误/警告时)
overlay: true,
},
proxy: mode === "development" ? {
"/api": {
target: env.VITE_API_BASE_URL || "http://192.168.110.84:8000", // 从环境变量读取,默认为本地后端
changeOrigin: true,
bypass: (req) => {
if (req.headers.accept?.includes('text/html')) return '/index.html'
},
},
'/uploads': {
target: env.VITE_API_BASE_URL ?? 'http://192.168.110.84:8000',
changeOrigin: true,
},
} : undefined, // 生产环境不启用代理
},
build: {
rollupOptions: {
output: {},
},
},
preview: {
port: 5173,
},
};
});