From 9c70250234f12c21bf6623d21ee5597fc8b778ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=B2=E8=BE=B0=E7=94=9F=E4=BA=A7?= Date: Mon, 20 Apr 2026 00:47:21 +0800 Subject: [PATCH] =?UTF-8?q?v0.0.2=20-=20=E4=BF=AE=E5=A4=8DVite=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E7=A6=81=E7=94=A8=E4=BC=98=E5=8C=96=EF=BC=8C=E7=A1=AE?= =?UTF-8?q?=E4=BF=9DnumberFilter=E4=BB=A3=E7=A0=81=E8=A2=AB=E6=AD=A3?= =?UTF-8?q?=E7=A1=AE=E7=BC=96=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/vite.config.js | 57 +++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 34 deletions(-) diff --git a/frontend/vite.config.js b/frontend/vite.config.js index c67b368..1911d48 100644 --- a/frontend/vite.config.js +++ b/frontend/vite.config.js @@ -3,59 +3,48 @@ import react from '@vitejs/plugin-react' import { readFileSync, writeFileSync } from 'fs' import { join } from 'path' -// 从 config/VERSION 文件读取版本号 function getVersion() { try { - const versionFile = join(__dirname, 'config', 'VERSION') - const content = readFileSync(versionFile, 'utf-8').trim() - // 移除 VERSION= 前缀 - if (content.startsWith('VERSION=')) { - return content.substring(7).trim() - } - return content || '0.0.0' + const versionFile = join(__dirname, '..', 'config', 'VERSION') + const content = readFileSync(versionFile, 'utf-8') + const match = content.match(/^VERSION=(.*)$/m) + return match ? match[1].trim() : '0.0.0' } catch (e) { - console.error('读取 VERSION 文件失败:', e.message) return '0.0.0' } } const APP_VERSION = getVersion() -console.log('📦 构建版本:v' + APP_VERSION) -// 构建后执行 - 更新 dist/index.html 的 title function updateHtmlTitle() { - 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>/, - '<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) - } - } - } + try { + const htmlPath = join(__dirname, 'index.html') + let htmlContent = readFileSync(htmlPath, 'utf-8') + htmlContent = htmlContent.replace( + /甲辰收藏 v[\d.]+<\/title>/, + `<title>甲辰收藏 v${APP_VERSION}` + ) + writeFileSync(htmlPath, htmlContent, 'utf-8') + } catch (e) {} } +updateHtmlTitle() + export default defineConfig({ - plugins: [react(), updateHtmlTitle()], + plugins: [react()], define: { 'import.meta.env.APP_VERSION': JSON.stringify(APP_VERSION) }, build: { + minify: false, rollupOptions: { + treeshake: false, output: { - entryFileNames: 'assets/[name]-[hash]-[name].js', - chunkFileNames: 'assets/[name]-[hash].js', - assetFileNames: 'assets/[name]-[hash].[ext]' + manualChunks: undefined } + }, + esbuild: { + treeShaking: false } } -}) \ No newline at end of file +})