-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathvite.config.ts
More file actions
51 lines (44 loc) · 1.26 KB
/
Copy pathvite.config.ts
File metadata and controls
51 lines (44 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { fileURLToPath, URL } from 'node:url'
import { execFileSync } from 'node:child_process'
import { readFileSync } from 'node:fs'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import tailwindcss from 'tailwindcss'
import autoprefixer from 'autoprefixer'
interface PackageMetadata {
version: string
}
const packageMetadata = JSON.parse(
readFileSync(fileURLToPath(new URL('./package.json', import.meta.url)), 'utf8')
) as PackageMetadata
const resolveGitCommit = () => {
if (process.env.VITE_GIT_COMMIT) return process.env.VITE_GIT_COMMIT
try {
return execFileSync('git', ['rev-parse', '--short=12', 'HEAD'], {
encoding: 'utf8',
stdio: ['ignore', 'pipe', 'ignore']
}).trim()
} catch {
return 'unknown'
}
}
const buildVersion = process.env.VITE_APP_VERSION || packageMetadata.version
const buildCommit = resolveGitCommit()
export default defineConfig({
define: {
__APP_VERSION__: JSON.stringify(buildVersion),
__GIT_COMMIT__: JSON.stringify(buildCommit)
},
plugins: [vue(), vueJsx()],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
},
css: {
postcss: {
plugins: [tailwindcss, autoprefixer]
}
}
})