Files
ele-HeiXiu/vite.config.ts
YoungestSongMo 3becdb85d4 feat: 实现设置页面 + 路由系统 + JWT认证体系 + 公告优化 + 错误类型系统
## 新增功能

### 设置页面(Router + Modal 叠加)
- HashRouter 路由系统,Electron file:// 协议兼容
- 设置页以居中 Modal 叠加首页,仅 X 按钮关闭
- 主题切换 Segmented 控件(与首页 Switch 共享 Context)
- 大模型产物存储仓库路径配置(原生文件夹选择对话框)
- 企业版额外:团队创作存储仓库路径
- 系统信息展示(平台/版本/版本类型/环境)
- 版本更新检查(状态机:idle→checking→no-update/available→downloading→downloaded→error)

### JWT 认证体系
- 双 Token 机制:access_token + refresh_token
- Axios 拦截器 401 自动刷新 + 并发请求去重队列
- 启动时 refresh_token 静默续期(自动登录)
- 记住密码:Base64 编码存储,表单自动回填
- setTokenRefreshHandler 解耦模式:request.ts 不知晓 auth

### 自定义错误类型系统
- RefreshError 继承 RequestError,type = AUTH_EXPIRED
- 全局拦截器捕获 RefreshError → 自动 clearToken + AUTH_REQUIRED
- 任何位置 throw new RefreshError() 即可触发登录 Modal

### 公告卡片优化
- 长文本 Tooltip 悬浮预览
- 点击卡片弹出详情 Modal(全文保留换行)

### SettingsContext(类似 Vue Pinia)
- 集中式设置状态管理
- localStorage 持久化:ele-heixiu-output-path / ele-heixiu-team-repo-path
- useSettings() 全局消费

## 架构变更
- App.tsx → HashRouter + AppRoutes + LoginPage 弹层
- Layout.tsx = NavBar + <Outlet /> 页面壳
- HomePage.tsx 从 App.tsx 提取
- NavBar 使用 useNavigate() 真实路由导航
- useUpdater 改为模块级单例 IPC 监听器(修复 MaxListenersExceededWarning)
- electron/main.ts 新增 FILE_DIALOG IPC handler

## 依赖
- 新增 react-router-dom
2026-06-03 19:25:15 +08:00

83 lines
2.7 KiB
TypeScript
Raw 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 } 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({
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'),
},
},
// ============================================================
// 开发服务器 & HMR 配置
// ============================================================
server: {
port: 5173,
strictPort: true,
host: 'localhost',
// 文件监听Windows 优化)
watch: {
// Windows 上默认的 fs.watch 有时不稳定,
// 如果文件保存后界面无反应,可临时开启 usePolling
// usePolling: true,
// interval: 100,
// 忽略不需要监听的目录,减少 CPU 占用
ignored: ['**/node_modules/**', '**/dist/**', '**/dist-electron/**', '**/release/**'],
},
// HMR 配置
hmr: {
// 在浏览器控制台显示 HMR 覆盖层(错误/警告时)
overlay: true,
// 协议默认 ws://localhost 下无需额外配置
},
},
build: {
rollupOptions: {
output: {},
},
},
preview: {
port: 5173,
},
});