-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
125 lines (122 loc) · 2.93 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
* SPDX-FileCopyrightText: 2023 Zextras <https://www.zextras.com>
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
/// <reference types="vitest" />
import react from '@vitejs/plugin-react-swc';
import { defineConfig, loadEnv, UserConfig } from 'vite';
import { viteStaticCopy } from 'vite-plugin-static-copy';
import pkg from './package.json';
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '');
const basePath = mode === 'production' || env.HOST ? '/files/public/link/access' : '';
const pkgRel = mode === 'development' ? Date.now() : 1;
const proxy: UserConfig['preview']['proxy'] = {};
if (mode !== 'production' && env.HOST) {
proxy['/static/iris'] = {
target: env.HOST,
secure: false,
changeOrigin: true
};
proxy['/services/files'] = {
target: env.HOST,
secure: false,
changeOrigin: true
};
}
return {
plugins: [
react(),
viteStaticCopy({
targets: [
{
src: 'package/PKGBUILD.template',
dest: 'package',
transform(content): string {
return content
.replace('{{name}}', pkg.name)
.replace('{{version}}', pkg.version)
.replace('{{rel}}', `${pkgRel}`)
.replace('{{description}}', pkg.description);
},
rename(filename, fileExt): string {
if (fileExt === 'template') {
return filename;
}
return `${filename}.${fileExt}`;
}
},
{
src: 'package/yap.json.template',
dest: '.',
transform(content): string {
return content
.replace('{{name}}', pkg.name)
.replace('{{version}}', pkg.version)
.replace('{{rel}}', `${pkgRel}`)
.replace('{{description}}', pkg.description);
},
rename(filename, fileExt): string {
if (fileExt === 'template') {
return filename;
}
return `${filename}.${fileExt}`;
}
}
]
})
],
base: basePath,
build: {
copyPublicDir: mode !== 'production' && (env.HOST ?? '').length === 0,
rollupOptions: {
output: {
manualChunks: (id): string | undefined => {
if (id.includes('node_modules')) {
return 'vendor';
}
return undefined;
}
}
}
},
preview: {
proxy
},
test: {
globals: true,
environment: 'jsdom',
restoreMocks: true,
setupFiles: ['./src/test/setup.ts'],
retry: 1,
server: {
deps: {
fallbackCJS: true
}
},
coverage: {
enabled: true,
provider: 'v8',
all: true,
clean: true,
include: [
'src/**',
'!src/mocks/*', // exclude msw handlers
'!src/@types/*', // exclude types
'!src/test/*', // exclude test folder
'!src/graphql/**', // exclude graphql folder
'!src/**/type*' // exclude type utils
],
reporter: ['text', 'cobertura', 'lcov'],
thresholds: {
branches: 75,
functions: 75,
lines: 75,
statements: 75
}
}
}
} satisfies UserConfig;
});