generated from graasp/graasp-repo
-
Notifications
You must be signed in to change notification settings - Fork 3
/
vite.config.ts
101 lines (97 loc) · 3.14 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
98
99
100
101
/// <reference types="./src/vite-env.d.ts"/>
import { TanStackRouterVite } from '@tanstack/router-plugin/vite';
import react from '@vitejs/plugin-react';
import { type UserConfigExport, defineConfig, loadEnv } from 'vite';
import checker from 'vite-plugin-checker';
import istanbul from 'vite-plugin-istanbul';
import { viteStaticCopy } from 'vite-plugin-static-copy';
import tsConfigPaths from 'vite-tsconfig-paths';
import { umamiPlugin } from './umami.plugin';
// https://vitejs.dev/config/
const config = ({ mode }: { mode: string }): UserConfigExport => {
process.env = {
VITE_VERSION: 'default',
VITE_BUILD_TIMESTAMP: new Date().toISOString(),
...process.env,
...loadEnv(mode, process.cwd()),
};
const {
VITE_PORT,
BROWSER,
VITE_UMAMI_WEBSITE_ID,
VITE_UMAMI_HOST,
VITE_GRAASP_API_HOST,
} = process.env;
// compute the port to use
const PORT = parseInt(VITE_PORT ?? '3114', 10);
// compute whether we should open the browser
// this defines if we should automatically open the browser
const shouldOpen = BROWSER && BROWSER !== 'none';
return defineConfig({
base: '/',
server: {
port: PORT,
// whether we should open the url on start
open: shouldOpen,
watch: {
ignored: ['**/coverage/**', '**/cypress/downloads/**'],
},
proxy: {
// send requests made to `/api` to the backend running on a different port
// this allows to how have to specify a different host on the requests
// in production the load balancer will play this role.
'/api': {
target: VITE_GRAASP_API_HOST ?? 'http://localhost:3000',
changeOrigin: true,
// remove the "api" part
rewrite: (path) => path.replace(/^\/api/, ''),
},
},
},
preview: {
port: PORT,
// forces to use the specified port
strictPort: true,
},
build: {
outDir: 'build',
},
plugins: [
TanStackRouterVite(),
tsConfigPaths({
projects: ['./tsconfig.json'],
}),
// the checker plugin is disabled when running the tests
mode !== 'test'
? checker({
typescript: true,
eslint: {
lintCommand: 'eslint "./**/*.{ts,tsx}"',
useFlatConfig: true,
},
overlay: { initialIsOpen: false, position: 'br' },
})
: istanbul({
include: 'src/*',
exclude: ['node_modules', 'test/', '.nyc_output', 'coverage'],
extension: ['.js', '.ts', '.tsx'],
requireEnv: false,
// forces to instrument code also in production build only if the mode is test
// this is useful when we want to build and preview in CI to have faster and more stable tests
forceBuildInstrument: mode === 'test',
checkProd: true,
}),
react(),
umamiPlugin({
websiteId: VITE_UMAMI_WEBSITE_ID,
host: VITE_UMAMI_HOST,
enableInDevMode: true,
requireInProduction: false,
}),
viteStaticCopy({
targets: [{ src: 'src/locales', dest: '' }],
}),
],
});
};
export default config;