-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathvite.config.ts
97 lines (87 loc) · 2.66 KB
/
vite.config.ts
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import { execSync } from 'node:child_process'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import Vue from '@vitejs/plugin-vue'
import VueJsx from '@vitejs/plugin-vue-jsx'
import UnoCSS from 'unocss/vite'
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'
import Components from 'unplugin-vue-components/vite'
import { defineConfig } from 'vite'
import pkg from './package.json'
const root = fileURLToPath(new URL('../../', import.meta.url))
const core = path.join(root, 'packages/core/src')
const shared = path.join(root, 'packages/shared/src')
const ui = path.join(root, 'packages/ui/src')
const { commitHash, commitDate, commitUrl, lastCommitMessage } = getGitInfo()
// https://vitejs.dev/config/
export default defineConfig({
resolve: {
alias: {
'@core': core,
'@shared': shared,
'@ui': ui,
},
},
plugins: [
Vue({
script: {
propsDestructure: true,
defineModel: true,
},
}),
VueJsx(),
// https://github.com/antfu/vite-plugin-components
Components({
dts: 'src/auto-components.d.ts',
dirs: [
'./src/components',
ui,
],
directoryAsNamespace: true,
resolvers: [
NaiveUiResolver(),
],
}),
// https://github.com/antfu/unocss
UnoCSS(),
],
define: {
__VERSION__: JSON.stringify(pkg.version),
__COMMIT_HASH__: JSON.stringify(commitHash),
__COMMIT_DATE__: JSON.stringify(commitDate),
__COMMIT_URL__: JSON.stringify(commitUrl),
__LAST_COMMIT_MESSAGE__: JSON.stringify(lastCommitMessage),
},
css: {
preprocessorOptions: {
scss: {
api: 'modern-compiler',
},
},
},
})
function getGitInfo() {
const repoUrl = 'https://github.com/Chilfish/Weibo-archiver/commit'
try {
const commitHash = execSync('git rev-parse --short HEAD').toString().trimEnd()
const commitUrl = `${repoUrl}/${commitHash}`
const commitDate = execSync('git log -1 --format=%cI').toString().trimEnd()
const lastCommitMessage = execSync('git show -s --format=%s').toString().trimEnd()
return { commitHash, commitDate, commitUrl, lastCommitMessage }
}
catch {
// https://vercel.com/docs/projects/environment-variables/system-environment-variables#VERCEL_GIT_COMMIT_SHA
const {
VERCEL_GIT_COMMIT_SHA: commitHash,
VERCEL_GIT_COMMIT_DATE: commitDate,
VERCEL_GIT_COMMIT_MESSAGE: lastCommitMessage,
} = process.env
const shortCommitHash = commitHash?.slice(0, 7)
return {
commitHash: shortCommitHash,
commitDate: commitDate || new Date().toISOString(),
commitUrl: `${repoUrl}/${shortCommitHash}`,
lastCommitMessage,
}
}
}