-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
57 lines (51 loc) 路 1.35 KB
/
Copy pathvite.config.js
File metadata and controls
57 lines (51 loc) 路 1.35 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
import { defineConfig } from 'vite';
import { sveltekit } from '@sveltejs/kit/vite';
import { execSync } from 'child_process';
import { readFileSync } from 'fs';
function getGitInfo() {
try {
return {
hash: execSync('git rev-parse HEAD').toString().trim(),
branch: execSync('git rev-parse --abbrev-ref HEAD').toString().trim(),
};
} catch {
return { hash: 'unknown', branch: 'unknown' };
}
}
function getVersion() {
try {
return JSON.parse(readFileSync('package.json', 'utf8')).version;
} catch {
return '0.0.0';
}
}
// https://vite.dev/config/
export default defineConfig(async () => {
const host = process.env.TAURI_DEV_HOST;
return {
plugins: [sveltekit()],
define: {
__DEV__: JSON.stringify(process.env.NODE_ENV !== 'production'),
__COMMIT_HASH__: JSON.stringify(getGitInfo().hash),
__GIT_BRANCH__: JSON.stringify(getGitInfo().branch),
__APP_VERSION__: JSON.stringify(getVersion()),
__BUILD_DATE__: JSON.stringify(new Date().toISOString().split('T')[0]),
},
clearScreen: false,
server: {
port: 1420,
strictPort: true,
host: host || '0.0.0.0',
hmr: host
? {
protocol: 'ws',
host: 'localhost',
port: 1421,
}
: true,
watch: {
ignored: ['**/src-tauri/**'],
},
},
};
});