- vite buildId 统一按 Asia/Shanghai 生成, CI(UTC) 与本地时区不再漂移 - index.html 加 viewport-fit=cover (env(safe-area-inset-*) 才生效) - app-shell 顶部 +20px+safe inset, bottom-nav 底部 +20px+safe inset 防状态栏/手势条遮内容 - 页面跳转加淡入上滑动画 (Layout 内嵌页面按 pathname 重挂载, Landing/Login 同款)
52 lines
1.8 KiB
TypeScript
52 lines
1.8 KiB
TypeScript
import { defineConfig, type Plugin } from "vite";
|
|
import react from "@vitejs/plugin-react";
|
|
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
import path from "node:path";
|
|
|
|
const host = process.env.TAURI_DEV_HOST;
|
|
|
|
function buildId() {
|
|
// YYYYMMDD.HHmmss: 每次构建生成新的 BUILD_ID, 用于 OTA/web 升级比对
|
|
// 统一按 UTC+8 (Asia/Shanghai) 取时, 避免 CI (UTC) 与本地时区漂移导致误判升级
|
|
const pad = (n: number) => String(n).padStart(2, "0");
|
|
const cn = new Date(Date.now() + 8 * 3600 * 1000);
|
|
return (
|
|
[cn.getUTCFullYear(), pad(cn.getUTCMonth() + 1), pad(cn.getUTCDate())].join("") +
|
|
"." +
|
|
[pad(cn.getUTCHours()), pad(cn.getUTCMinutes()), pad(cn.getUTCSeconds())].join("")
|
|
);
|
|
}
|
|
|
|
export default defineConfig(async () => {
|
|
const pkg = JSON.parse(readFileSync(new URL("./package.json", import.meta.url), "utf8"));
|
|
|
|
// 构建完成后把 BUILD_ID 写进 dist/.build-id, 供 server 的 /api/ota/manifest-web
|
|
// 返回"当前部署版本"的 build_id, 让 web 端升级提示只在真是新部署时出现
|
|
const writeBuildId: Plugin = {
|
|
name: "wardrobe:write-build-id",
|
|
closeBundle() {
|
|
const dir = path.resolve(process.cwd(), "dist");
|
|
mkdirSync(dir, { recursive: true });
|
|
writeFileSync(path.join(dir, ".build-id"), buildId(), "utf8");
|
|
},
|
|
};
|
|
|
|
return {
|
|
plugins: [react(), writeBuildId],
|
|
clearScreen: false,
|
|
server: {
|
|
port: 1420,
|
|
strictPort: true,
|
|
host: host || false,
|
|
hmr: host ? { protocol: "ws", host, port: 1421 } : undefined,
|
|
watch: {
|
|
ignored: ["**/src-tauri/**"],
|
|
},
|
|
},
|
|
// 编译期常量: 版本 + 构建号, 供 src/version.ts 使用
|
|
define: {
|
|
__BUILD_ID__: JSON.stringify(buildId()),
|
|
__APP_VERSION__: JSON.stringify(pkg.version || "0.0.0"),
|
|
},
|
|
};
|
|
}); |