v1.2.98 - 修复前端构建版本号不更新问题

This commit is contained in:
甲辰生产 2026-04-19 21:11:49 +08:00
parent d578289c7c
commit fb987dc5b9
1 changed files with 19 additions and 17 deletions

View File

@ -22,10 +22,13 @@ function getVersion() {
const APP_VERSION = getVersion()
console.log('📦 构建版本v' + APP_VERSION)
// 构建时自动更新 index.html 的 title
// 构建后执行 - 更新 dist/index.html 的 title
function updateHtmlTitle() {
return {
name: 'update-html-title',
closeBundle() {
try {
const htmlPath = join(__dirname, 'index.html')
const htmlPath = join(__dirname, 'dist', 'index.html')
let htmlContent = readFileSync(htmlPath, 'utf-8')
// 替换 <title>甲辰收藏 vXXX</title>
htmlContent = htmlContent.replace(
@ -33,17 +36,16 @@ function updateHtmlTitle() {
'<title>甲辰收藏 v' + APP_VERSION + '</title>'
)
writeFileSync(htmlPath, htmlContent, 'utf-8')
console.log('✅ 已更新 index.html title: 甲辰收藏 v' + APP_VERSION)
console.log('✅ 已更新 dist/index.html title: 甲辰收藏 v' + APP_VERSION)
} catch (e) {
console.error('更新 index.html 失败:', e.message)
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)
},