-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathvite.config.ts
More file actions
82 lines (75 loc) · 2.21 KB
/
vite.config.ts
File metadata and controls
82 lines (75 loc) · 2.21 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import react from '@vitejs/plugin-react';
import browserslistToEsbuild from 'browserslist-to-esbuild';
import { PluginOption, defineConfig, loadEnv } from 'vite';
/* See https://stackoverflow.com/questions/69626090/how-to-watch-public-directory-in-vite-project-for-hot-reload allows
hot reloading when json files are modifeid in the public folder*/
function jsonHMR(): PluginOption {
return {
name: 'json-hmr',
enforce: 'post',
handleHotUpdate({ file, server }) {
if (file.endsWith('.json')) {
console.log('reloading json file...');
server.ws.send({
type: 'full-reload',
path: '*',
});
}
},
};
}
// Obtain default coverage config from vitest when not building for production
// (to avoid importing vitest during build as its a dev dependency)
let vitestCoverageConfigDefaultsExclude: string[] = [];
if (process.env.NODE_ENV !== 'production') {
await import('vitest/config').then((vitestConfig) => {
vitestCoverageConfigDefaultsExclude =
vitestConfig.coverageConfigDefaults.exclude;
});
}
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '');
const plugins: PluginOption[] = [react()];
// Allow hot reloading of json files in public folder when in development
if (env.NODE_ENV === 'development') plugins.push(jsonHMR());
return {
plugins: plugins,
server: {
port: 3000,
},
preview: {
port: 5001,
},
build: {
// Use browserslist config
target: browserslistToEsbuild(),
},
test: {
globals: true,
environment: 'jsdom',
setupFiles: ['src/setupTests.ts'],
coverage: {
reporter: [
// Default
'text',
'html',
'clover',
'json',
// Extra for VSCode extension
['lcov', { outputFile: 'lcov.info', silent: true }],
],
exclude: [
...vitestCoverageConfigDefaultsExclude,
'public/*',
'server/*',
'__mocks__/axios.ts',
'micro-frontend-tools/serve-plugins.js',
'.eslintrc.cjs',
'src/vite-env.d.ts',
'src/main.tsx',
],
},
},
};
});