-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
54 lines (48 loc) · 1.5 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
import { execSync } from 'node:child_process'
import path from 'path'
import react from '@vitejs/plugin-react-swc'
import { defineConfig, loadEnv } from 'vite'
import { analyzer } from 'vite-bundle-analyzer'
import arraybuffer from 'vite-plugin-arraybuffer'
import fullreload from 'vite-plugin-full-reload'
import mkcert from 'vite-plugin-mkcert'
import pkg from './package.json'
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
const envprefix = 'ZSS_'
const root = path.join('zss', 'terminal')
const apppath = path.join(process.cwd(), root)
// Load app-level env vars to node-level env vars.
process.env = {
...process.env,
ZSS_BRANCH_NAME: execSync('git rev-parse --abbrev-ref HEAD')
.toString()
.trimEnd(),
ZSS_BRANCH_VERSION: pkg.version,
ZSS_COMMIT_HASH: execSync('git rev-parse HEAD').toString().trimEnd(),
ZSS_COMMIT_MESSAGE: execSync('git show -s --format=%s')
.toString()
.trimEnd(),
...loadEnv(mode, apppath, envprefix),
}
const hmronly = !!JSON.parse(process.env.ZSS_HMR_ONLY ?? '')
const useanalyzer = !!JSON.parse(process.env.ZSS_ANALYZER ?? '')
console.info({ hmronly, analyzer })
return {
root,
envPrefix: envprefix,
plugins: [
react(),
arraybuffer(),
mkcert(),
...(hmronly ? [] : [fullreload(['**/*.ts', '**/*.tsx'])]),
...(useanalyzer ? [analyzer()] : []),
// ,
],
resolve: {
alias: {
zss: path.resolve(__dirname, './zss'),
},
},
}
})