feat: add version and git hash to application title

Add a custom Vite plugin to transform index.html and include version number and git hash in the application title for better traceability.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Misaka_Company
2026-03-18 10:44:19 +08:00
parent 64349125ba
commit 851c2ce634

View File

@@ -3,6 +3,7 @@ import { defineConfig } from 'electron-vite'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'
import { execSync } from 'child_process'
import { createRequire } from 'module'
// Get git hash (first 7 characters)
const getGitHash = (): string => {
@@ -14,6 +15,7 @@ const getGitHash = (): string => {
}
// Get version from package.json
const require = createRequire(import.meta.url)
const version = require('./package.json').version
const gitHash = getGitHash()
@@ -30,6 +32,18 @@ export default defineConfig({
'@renderer': resolve('src/renderer/src')
}
},
plugins: [react(), tailwindcss()]
plugins: [
react(),
tailwindcss(),
{
name: 'update-title',
transformIndexHtml(html) {
return html.replace(
'<title>ERP Auto Tool</title>',
`<title>ERPAuto - v${version}(${gitHash})</title>`
)
}
}
]
}
})