- Landing: 移除 header 登录/进入应用按钮、hero 在线体验入口 - 下载区: 复制链接行改为 qrcode.react 二维码 (扫码下载 APK) - 修复 '持续提示新版本可用' bug: vite 构建时把 BUILD_ID 写入 dist/.build-id, manifest-web 返回当前部署 dist 的 build_id, 与浏览器内置值同源比对; 此前返回 OTA 包 build_id (seq-<ts>) 与页面 BUILD_ID 永不一致 → 横幅常驻
51 lines
1.7 KiB
TypeScript
51 lines
1.7 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 升级比对
|
|
const d = new Date();
|
|
const pad = (n: number) => String(n).padStart(2, "0");
|
|
return (
|
|
[d.getFullYear(), pad(d.getMonth() + 1), pad(d.getDate())].join("") +
|
|
"." +
|
|
[pad(d.getHours()), pad(d.getMinutes()), pad(d.getSeconds())].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"),
|
|
},
|
|
};
|
|
}); |