Skip to content

Commit c69df67

Browse files
committed
build(vite): use async config
1 parent 932f64a commit c69df67

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

vite.config.mts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { execSync } from 'node:child_process'
1+
import * as child_process from 'node:child_process'
22
import { join } from 'node:path'
3+
import { promisify } from 'node:util'
34

45
import react from '@vitejs/plugin-react'
56
import unocss from 'unocss/vite'
@@ -8,22 +9,27 @@ import { VitePWA as pwa } from 'vite-plugin-pwa'
89

910
import { description, name, version } from './package.json'
1011

11-
const getCommitHash = (): string => execSync('git rev-parse --short HEAD').toString().trimEnd()
12+
const exec = promisify(child_process.exec)
1213

13-
const getCommitDate = (): string => {
14-
const commitDate = execSync('git log -1 --format=%cd').toString()
15-
return new Date(commitDate).toISOString()
14+
const getCommitHash = async () => {
15+
const { stdout } = await exec('git rev-parse --short HEAD')
16+
return stdout.trim()
1617
}
1718

18-
export default defineConfig({
19+
const getCommitDate = async () => {
20+
const { stdout } = await exec('git log -1 --format=%cd')
21+
return new Date(stdout).toISOString()
22+
}
23+
24+
export default defineConfig(async () => ({
1925
base: './',
2026
build: {
2127
chunkSizeWarningLimit: 1000,
2228
},
2329
define: {
2430
__VERSION__: JSON.stringify(version),
25-
__COMMIT_HASH__: JSON.stringify(getCommitHash()),
26-
__COMMIT_DATE__: JSON.stringify(getCommitDate()),
31+
__COMMIT_HASH__: JSON.stringify(await getCommitHash()),
32+
__COMMIT_DATE__: JSON.stringify(await getCommitDate()),
2733
},
2834
plugins: [
2935
react(),
@@ -82,4 +88,4 @@ export default defineConfig({
8288
ignored: [/coverage/, /dist/],
8389
},
8490
},
85-
})
91+
}))

0 commit comments

Comments
 (0)