怎加版本

This commit is contained in:
cheney
2026-08-06 17:27:23 +08:00
parent 4f39f428bd
commit f2e53df25b
4 changed files with 26 additions and 0 deletions
+12
View File
@@ -1,12 +1,24 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
// 每次编译生成唯一 build 号 (YYYYMMDD.HHmmss), 通过 define 注入到 __BUILD_ID__
// 版本号 APP_VERSION 唯一管理点在 package.json 的 version 字段 (手动修改)
function makeBuildId() {
const d = new Date()
const p = (n, w) => String(n).padStart(w || 2, '0')
return `${d.getFullYear()}${p(d.getMonth() + 1)}${p(d.getDate())}.${p(d.getHours())}${p(d.getMinutes())}${p(d.getSeconds())}`
}
const BUILD_ID = makeBuildId()
// 移动端优先: 默认按移动视口开发, 同时兼容桌面浏览器
// HMR 走 WebSocket; 某些受限 webview (VS Code Simple Browser / 老版 Android WebView) 不支持,
// 此时 Vite 会自动降级为整页刷新兜底 (full-reload 与 HMR 共用同一 WS 通道)。
// 注意: 不能设 hmr: false —— 那会连 WS 通道一起关掉, 文件变更不再触发任何刷新。
export default defineConfig({
plugins: [react()],
define: {
__BUILD_ID__: JSON.stringify(BUILD_ID), // 构建时生成的唯一 build 号
},
server: {
host: '0.0.0.0',
port: 5173,