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>/,
- '甲辰收藏 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>/,
+ '甲辰收藏 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)
},