Repository navigation
Expand file tree
/
Copy pathvite.config.ts
More file actions
61 lines (56 loc) · 1.79 KB
/
Copy pathvite.config.ts
File metadata and controls
61 lines (56 loc) · 1.79 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
52
53
54
55
56
57
58
59
60
61
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'
import { execSync } from 'child_process'
// Get git information at build time
const getGitInfo = () => {
try {
const gitCommit = execSync('git rev-parse HEAD', {
encoding: 'utf8',
}).trim()
const gitBranch = execSync('git rev-parse --abbrev-ref HEAD', {
encoding: 'utf8',
}).trim()
return { gitCommit, gitBranch }
} catch (error) {
console.warn('Could not get git info:', error)
return { gitCommit: 'unknown', gitBranch: 'unknown' }
}
}
// https://vitejs.dev/config/
export default defineConfig(async () => {
const { gitCommit, gitBranch } = getGitInfo()
const buildDate = new Date().toISOString()
const devHost = process.env.TAURI_DEV_HOST || '127.0.0.1'
return {
plugins: [react(), tailwindcss()],
// Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`
//
// 1. prevent vite from obscuring rust errors
clearScreen: false,
// 2. tauri expects a fixed port, fail if that port is not available
server: {
host: devHost,
hmr: {
host: devHost,
port: 1421,
protocol: 'ws',
},
port: 1420,
strictPort: true,
watch: {
ignored: ['**/src-tauri/target/**'],
},
},
// 3. to make use of `TAURI_DEBUG` and other env variables
// https://tauri.studio/v1/api/config#buildconfig.beforedevcommand
envPrefix: ['VITE_', 'TAURI_'],
// 4. Define build-time constants
define: {
__GIT_COMMIT__: JSON.stringify(gitCommit),
__GIT_BRANCH__: JSON.stringify(gitBranch),
__BUILD_DATE__: JSON.stringify(buildDate),
__NODE_ENV__: JSON.stringify(process.env.NODE_ENV || 'development'),
},
}
})