Skip to content

Commit ab9ab3c

Browse files
Claudewuhan005
andauthored
Auto-inject commit SHA during Vite build from git (#74)
* feat: auto-set VITE_COMMIT_SHA from git during build Agent-Logs-Url: https://github.com/wuhan005/NekoBox/sessions/522aa6e7-3040-491c-a0a8-b89801d8268b Co-authored-by: wuhan005 <12731778+wuhan005@users.noreply.github.com> * fix: handle TypeScript error type in catch block Agent-Logs-Url: https://github.com/wuhan005/NekoBox/sessions/14fb2b39-6334-415c-8b67-b0af038a74bc Co-authored-by: wuhan005 <12731778+wuhan005@users.noreply.github.com> --------- Co-authored-by: anthropic-code-agent[bot] <242468646+Claude@users.noreply.github.com> Co-authored-by: wuhan005 <12731778+wuhan005@users.noreply.github.com>
1 parent 1065917 commit ab9ab3c

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

web/vite.config.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
import {resolve} from 'path'
22
import {defineConfig} from 'vite'
33
import vue from '@vitejs/plugin-vue'
4+
import {execSync} from 'child_process'
5+
6+
// Get commit SHA at build time
7+
function getCommitSHA() {
8+
try {
9+
return execSync('git rev-parse HEAD', {encoding: 'utf-8'}).trim()
10+
} catch (error) {
11+
console.warn('Warning: Could not get git commit SHA:', error instanceof Error ? error.message : String(error))
12+
return process.env.VITE_COMMIT_SHA || ''
13+
}
14+
}
415

516
// https://vite.dev/config/
617
export default defineConfig({
@@ -14,6 +25,11 @@ export default defineConfig({
1425
},
1526
},
1627

28+
// Define environment variables at build time
29+
define: {
30+
'import.meta.env.VITE_COMMIT_SHA': JSON.stringify(process.env.VITE_COMMIT_SHA || getCommitSHA()),
31+
},
32+
1733
server: {
1834
port: 3000,
1935
host: '0.0.0.0',

0 commit comments

Comments
 (0)