v0.0.2 - 修复Vite配置禁用优化,确保numberFilter代码被正确编译

This commit is contained in:
甲辰生产 2026-04-20 00:47:21 +08:00
parent 64776a6e14
commit 9c70250234
1 changed files with 23 additions and 34 deletions

View File

@ -3,59 +3,48 @@ import react from '@vitejs/plugin-react'
import { readFileSync, writeFileSync } from 'fs' import { readFileSync, writeFileSync } from 'fs'
import { join } from 'path' import { join } from 'path'
// 从 config/VERSION 文件读取版本号
function getVersion() { function getVersion() {
try { try {
const versionFile = join(__dirname, 'config', 'VERSION') const versionFile = join(__dirname, '..', 'config', 'VERSION')
const content = readFileSync(versionFile, 'utf-8').trim() const content = readFileSync(versionFile, 'utf-8')
// 移除 VERSION= 前缀 const match = content.match(/^VERSION=(.*)$/m)
if (content.startsWith('VERSION=')) { return match ? match[1].trim() : '0.0.0'
return content.substring(7).trim()
}
return content || '0.0.0'
} catch (e) { } catch (e) {
console.error('读取 VERSION 文件失败:', e.message)
return '0.0.0' return '0.0.0'
} }
} }
const APP_VERSION = getVersion() const APP_VERSION = getVersion()
console.log('📦 构建版本v' + APP_VERSION)
// 构建后执行 - 更新 dist/index.html 的 title
function updateHtmlTitle() { function updateHtmlTitle() {
return { try {
name: 'update-html-title', const htmlPath = join(__dirname, 'index.html')
closeBundle() { let htmlContent = readFileSync(htmlPath, 'utf-8')
try { htmlContent = htmlContent.replace(
const htmlPath = join(__dirname, 'dist', 'index.html') /<title>甲辰收藏 v[\d.]+<\/title>/,
let htmlContent = readFileSync(htmlPath, 'utf-8') `<title>甲辰收藏 v${APP_VERSION}</title>`
// 替换 <title>甲辰收藏 vXXX</title> )
htmlContent = htmlContent.replace( writeFileSync(htmlPath, htmlContent, 'utf-8')
/<title>甲辰收藏 v[\d.]+<\/title>/, } catch (e) {}
'<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({ export default defineConfig({
plugins: [react(), updateHtmlTitle()], plugins: [react()],
define: { define: {
'import.meta.env.APP_VERSION': JSON.stringify(APP_VERSION) 'import.meta.env.APP_VERSION': JSON.stringify(APP_VERSION)
}, },
build: { build: {
minify: false,
rollupOptions: { rollupOptions: {
treeshake: false,
output: { output: {
entryFileNames: 'assets/[name]-[hash]-[name].js', manualChunks: undefined
chunkFileNames: 'assets/[name]-[hash].js',
assetFileNames: 'assets/[name]-[hash].[ext]'
} }
},
esbuild: {
treeShaking: false
} }
} }
}) })