-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvite.config.ts
129 lines (121 loc) · 2.87 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
126
127
128
129
import fs from 'node:fs/promises';
import path from 'node:path';
import { sentryVitePlugin } from '@sentry/vite-plugin';
import react from '@vitejs/plugin-react';
import dotenv from 'dotenv';
import { Plugin } from 'vite';
import preload from 'vite-plugin-preload';
import svgr from 'vite-plugin-svgr';
import tsconfigPaths from 'vite-tsconfig-paths';
import { defineConfig } from 'vitest/config';
dotenv.config();
export default defineConfig({
plugins: [
tsconfigPaths(),
react(),
svgr({
svgrOptions: {
ref: true,
plugins: ['@svgr/plugin-svgo', '@svgr/plugin-jsx'],
svgoConfig: {
plugins: [
{
name: 'preset-default',
params: {
overrides: {
removeViewBox: false,
cleanupIds: false,
},
},
},
'prefixIds',
],
},
},
}),
preload(),
outputFile({
filePath: 'robots.txt',
content() {
const disallow = () => {
if (process.env.VITE_ENVIRONMENT !== 'production') {
return 'Disallow: /';
}
return `Disallow:`;
};
return ['User-agent: *', disallow(), ''].join('\n');
},
}),
outputFile({
filePath: 'version.txt',
content: () => process.env.VITE_APP_VERSION ?? 'unknown',
}),
sentryVitePlugin({
org: 'gokoyeb',
project: 'kdx',
authToken: process.env.SENTRY_AUTH_TOKEN,
release: { name: process.env.VITE_APP_VERSION },
silent: true,
telemetry: false,
}),
],
base: '/',
build: {
outDir: 'dist',
emptyOutDir: true,
sourcemap: true,
rollupOptions: {
output: {
manualChunks: {
xterm: ['@xterm/xterm'],
nivo: ['@nivo/line', '@nivo/bar'],
analytics: ['@sentry/react', 'posthog-js'],
vendors: [
'@floating-ui/react',
'ansi_up',
'downshift',
'react-hook-form',
'react-intl',
'tldts',
'unique-names-generator',
'zod',
'lodash-es',
],
},
},
},
},
server: {
port: 8000,
proxy: {
'/v1': 'https://staging.koyeb.com',
},
},
preview: {
port: 3000,
},
test: {
watch: false,
environment: 'happy-dom',
reporters: 'verbose',
dir: 'src',
setupFiles: ['src/vitest.setup.ts'],
restoreMocks: true,
},
});
type OutputFileOptions = {
filePath: string;
content: () => string;
};
function outputFile({ filePath, content }: OutputFileOptions): Plugin {
let dist = '';
return {
name: 'outputFile',
configResolved(config) {
dist = path.resolve(config.root, config.build.outDir);
},
async closeBundle() {
await fs.writeFile(path.join(dist, filePath), content());
},
};
}