From fb987dc5b914b61af22fe3fab2fc6e8665c14b54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=B2=E8=BE=B0=E7=94=9F=E4=BA=A7?= Date: Sun, 19 Apr 2026 21:11:49 +0800 Subject: [PATCH] =?UTF-8?q?v1.2.98=20-=20=E4=BF=AE=E5=A4=8D=E5=89=8D?= =?UTF-8?q?=E7=AB=AF=E6=9E=84=E5=BB=BA=E7=89=88=E6=9C=AC=E5=8F=B7=E4=B8=8D?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/vite.config.js | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/frontend/vite.config.js b/frontend/vite.config.js index a2b9451..6d12a05 100644 --- a/frontend/vite.config.js +++ b/frontend/vite.config.js @@ -22,28 +22,30 @@ function getVersion() { const APP_VERSION = getVersion() console.log('📦 构建版本:v' + APP_VERSION) -// 构建时自动更新 index.html 的 title +// 构建后执行 - 更新 dist/index.html 的 title function updateHtmlTitle() { - try { - const htmlPath = join(__dirname, 'index.html') - let htmlContent = readFileSync(htmlPath, 'utf-8') - // 替换 甲辰收藏 vXXX - htmlContent = htmlContent.replace( - /甲辰收藏 v[\d.]+<\/title>/, - '<title>甲辰收藏 v' + APP_VERSION + '' - ) - writeFileSync(htmlPath, htmlContent, 'utf-8') - console.log('✅ 已更新 index.html title: 甲辰收藏 v' + APP_VERSION) - } catch (e) { - console.error('更新 index.html 失败:', e.message) + return { + name: 'update-html-title', + closeBundle() { + try { + const htmlPath = join(__dirname, 'dist', 'index.html') + let htmlContent = readFileSync(htmlPath, 'utf-8') + // 替换 甲辰收藏 vXXX + htmlContent = htmlContent.replace( + /甲辰收藏 v[\d.]+<\/title>/, + '<title>甲辰收藏 v' + APP_VERSION + '' + ) + writeFileSync(htmlPath, htmlContent, 'utf-8') + console.log('✅ 已更新 dist/index.html title: 甲辰收藏 v' + APP_VERSION) + } catch (e) { + console.error('更新 dist/index.html 失败:', e.message) + } + } } } -// 构建前执行 -updateHtmlTitle() - export default defineConfig({ - plugins: [react()], + plugins: [react(), updateHtmlTitle()], define: { 'import.meta.env.APP_VERSION': JSON.stringify(APP_VERSION) },