v1.2.98 - 修复前端构建版本号不更新问题
This commit is contained in:
parent
d578289c7c
commit
fb987dc5b9
|
|
@ -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')
|
||||
// 替换 <title>甲辰收藏 vXXX</title>
|
||||
htmlContent = htmlContent.replace(
|
||||
/<title>甲辰收藏 v[\d.]+<\/title>/,
|
||||
'<title>甲辰收藏 v' + APP_VERSION + '</title>'
|
||||
)
|
||||
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')
|
||||
// 替换 <title>甲辰收藏 vXXX</title>
|
||||
htmlContent = htmlContent.replace(
|
||||
/<title>甲辰收藏 v[\d.]+<\/title>/,
|
||||
'<title>甲辰收藏 v' + APP_VERSION + '</title>'
|
||||
)
|
||||
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)
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in New Issue