-
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathvite.config.ts
More file actions
66 lines (58 loc) · 1.45 KB
/
Copy pathvite.config.ts
File metadata and controls
66 lines (58 loc) · 1.45 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
62
63
64
65
66
import ViteYaml from '@modyfi/vite-plugin-yaml';
import react from '@vitejs/plugin-react';
import { execSync } from 'child_process';
import { defineConfig } from 'vite';
import { VitePWA } from 'vite-plugin-pwa';
import viteTsconfigPaths from 'vite-tsconfig-paths';
function getGitCommitHash() {
return execSync('git rev-parse --short HEAD').toString().trim();
}
function getGitTag() {
try {
return execSync('git describe --tags --abbrev=0').toString().trim();
} catch {
return null;
}
}
const GIT_COMMIT = getGitCommitHash();
const GIT_TAG = getGitTag();
const getAppEnvironment = (mode: string) => {
if (process.env.VITE_APP_ENV) {
return process.env.VITE_APP_ENV;
}
if (process.env.BRANCH === 'main') {
return 'production';
}
if (process.env.BRANCH === 'beta') {
return 'beta';
}
return process.env.CONTEXT || mode;
};
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => ({
plugins: [
react(),
viteTsconfigPaths(),
ViteYaml(),
VitePWA({
registerType: 'prompt',
workbox: {
importScripts: ['notification-sw.js'],
},
}),
],
build: {
rollupOptions: {
output: {
manualChunks: {
react: ['react', 'react-dom', 'react-router-dom'],
},
},
},
},
define: {
__APP_ENV__: JSON.stringify(getAppEnvironment(mode)),
__GIT_COMMIT__: JSON.stringify(GIT_COMMIT),
__GIT_TAG__: JSON.stringify(GIT_TAG || ''),
},
}));