refactor: improve version management

- Move version number from env to package.json
- Add dynamic version loading with fallback
- Improve error handling for version loading
This commit is contained in:
Zhenye Dong
2024-11-10 17:57:05 +08:00
parent 47b8d97420
commit 734f60593a

View File

@@ -548,7 +548,15 @@ const BLOG = {
process.env.npm_lifecycle_event === 'export', // 在打包过程中默认开启缓存,开发或运行时开启此功能意义不大。
isProd: process.env.VERCEL_ENV === 'production' || process.env.EXPORT, // distinguish between development and production environment (ref: https://vercel.com/docs/environment-variables#system-environment-variables)
BUNDLE_ANALYZER: process.env.ANALYZE === 'true' || false, // 是否展示编译依赖内容与大小
VERSION: process.env.NEXT_PUBLIC_VERSION // 版本号
VERSION: (() => {
try {
// 优先使用环境变量否则从package.json中获取版本号
return process.env.NEXT_PUBLIC_VERSION || require('./package.json').version
} catch (error) {
console.warn('Failed to load package.json version:', error)
return '1.0.0' // 缺省版本号
}
})()
}
module.exports = BLOG