Skip to content

Commit

Permalink
build(vite): use async config
Browse files Browse the repository at this point in the history
  • Loading branch information
exuanbo committed Dec 9, 2023
1 parent 932f64a commit c69df67
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions vite.config.mts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { execSync } from 'node:child_process'
import * as child_process from 'node:child_process'
import { join } from 'node:path'
import { promisify } from 'node:util'

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

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

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

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

export default defineConfig({
const getCommitDate = async () => {
const { stdout } = await exec('git log -1 --format=%cd')
return new Date(stdout).toISOString()
}

export default defineConfig(async () => ({
base: './',
build: {
chunkSizeWarningLimit: 1000,
},
define: {
__VERSION__: JSON.stringify(version),
__COMMIT_HASH__: JSON.stringify(getCommitHash()),
__COMMIT_DATE__: JSON.stringify(getCommitDate()),
__COMMIT_HASH__: JSON.stringify(await getCommitHash()),
__COMMIT_DATE__: JSON.stringify(await getCommitDate()),
},
plugins: [
react(),
Expand Down Expand Up @@ -82,4 +88,4 @@ export default defineConfig({
ignored: [/coverage/, /dist/],
},
},
})
}))

0 comments on commit c69df67

Please sign in to comment.