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>
50 lines
1.2 KiB
TypeScript
50 lines
1.2 KiB
TypeScript
import { resolve } from 'path'
|
|
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 => {
|
|
try {
|
|
return execSync('git rev-parse --short=7 HEAD', { encoding: 'utf-8' }).trim()
|
|
} catch {
|
|
return 'unknown'
|
|
}
|
|
}
|
|
|
|
// Get version from package.json
|
|
const require = createRequire(import.meta.url)
|
|
const version = require('./package.json').version
|
|
const gitHash = getGitHash()
|
|
|
|
export default defineConfig({
|
|
main: {},
|
|
preload: {},
|
|
renderer: {
|
|
define: {
|
|
__APP_VERSION__: JSON.stringify(version),
|
|
__GIT_HASH__: JSON.stringify(gitHash)
|
|
},
|
|
resolve: {
|
|
alias: {
|
|
'@renderer': resolve('src/renderer/src')
|
|
}
|
|
},
|
|
plugins: [
|
|
react(),
|
|
tailwindcss(),
|
|
{
|
|
name: 'update-title',
|
|
transformIndexHtml(html) {
|
|
return html.replace(
|
|
'<title>ERP Auto Tool</title>',
|
|
`<title>ERPAuto - v${version}(${gitHash})</title>`
|
|
)
|
|
}
|
|
}
|
|
]
|
|
}
|
|
})
|