fix(frontend): 同步关于页版本号

This commit is contained in:
techotaku39
2026-05-26 15:54:05 +08:00
parent f2d8ece0c1
commit 9d1a7cd699
6 changed files with 42 additions and 1 deletions

View File

@@ -5,6 +5,10 @@
ARG BASE_REGISTRY=docker.io
FROM ${BASE_REGISTRY}/library/node:20-alpine AS builder
# 可由发布 workflow 从 git tag 注入,用于前端 About 页展示版本;未传时由 Vite 回退读取 tauri.conf.json。
ARG VITE_APP_VERSION=
ENV VITE_APP_VERSION=${VITE_APP_VERSION}
# pnpm pin 到 9.xlockfile 是 v9 生成pnpm 11 要求 Node 22+ 与 node:20 不兼容
RUN corepack enable && corepack prepare pnpm@9.15.0 --activate

View File

@@ -8,6 +8,7 @@ import logo from '@/assets/icon.svg'
import wechatQr from '@/assets/wechat.png'
export default function AboutPage() {
const appVersion = __APP_VERSION__
const images = [
'https://common-1304618721.cos.ap-chengdu.myqcloud.com/20250504102850.png',
'https://common-1304618721.cos.ap-chengdu.myqcloud.com/20250504103028.png',
@@ -27,7 +28,7 @@ export default function AboutPage() {
height={50}
className="rounded-lg"
/>
<h1 className="text-4xl font-bold">BiliNote v2.0.0</h1>
<h1 className="text-4xl font-bold">BiliNote v{appVersion}</h1>
</div>
<p className="text-muted-foreground mb-6 text-xl italic">
AI AI

View File

@@ -1 +1,3 @@
/// <reference types="vite/client" />
declare const __APP_VERSION__: string

View File

@@ -1,11 +1,25 @@
import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react'
import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
import tailwindcss from '@tailwindcss/vite'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
function readAppVersion() {
const fallbackVersion = '0.0.0'
try {
const tauriConfigPath = path.resolve(__dirname, 'src-tauri/tauri.conf.json')
const tauriConfig = JSON.parse(fs.readFileSync(tauriConfigPath, 'utf-8')) as { version?: string }
return tauriConfig.version || fallbackVersion
}
catch {
return fallbackVersion
}
}
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
// 在 Docker 环境中,父目录可能没有 .env 文件,使用当前目录
@@ -14,9 +28,13 @@ export default defineConfig(({ mode }) => {
const apiBaseUrl = env.VITE_API_BASE_URL || 'http://127.0.0.1:8483'
const port = parseInt(env.VITE_FRONTEND_PORT || '3015', 10)
const appVersion = env.VITE_APP_VERSION || process.env.VITE_APP_VERSION || readAppVersion()
return {
base: './',
define: {
__APP_VERSION__: JSON.stringify(appVersion),
},
plugins: [react(), tailwindcss()],
resolve: {
alias: {