-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
79 lines (75 loc) · 1.92 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
/// <reference types="vitest" />
import { defineConfig } from 'vite';
import { dependencies } from './package.json';
import react from '@vitejs/plugin-react';
import tsconfigPaths from 'vite-tsconfig-paths';
import svgr from 'vite-plugin-svgr';
import viteCompression from 'vite-plugin-compression';
import dotenv from 'dotenv';
dotenv.config();
export default ({ mode }) => {
return defineConfig({
plugins: [
react({
fastRefresh: process.env.NODE_ENV !== 'test',
}),
tsconfigPaths(),
svgr({
svgrOptions: {
icon: true,
},
}),
viteCompression({
verbose: false,
algorithm: 'gzip',
ext: '.gz',
}),
viteCompression({
verbose: true,
algorithm: 'brotliCompress',
ext: '.br',
}),
],
base: '/',
server: {
port: Number(process.env.PORT || 3001),
},
preview: {
port: 8080,
},
test: {
globals: true,
environment: 'jsdom',
setupFiles: 'src/setupTests.ts',
},
build: {
outDir: 'build',
reportCompressedSize: false,
sourcemap: false,
rollupOptions: {
output: {
manualChunks: {
vendor: ['react', 'react-router-dom', 'react-dom'],
...renderChunks(dependencies),
},
},
},
},
// NOTE: handle env variables here if you're using jest since import.meta conflicts with jest
define: {
'process.env.MODE': `"${mode}"`,
// 'process.env.VITE_ENV': `"${process.env.VITE_ENV}"`,
// 'process.env.VITE_API_URL': `"${process.env.VITE_API_URL}"`,
// 'process.env.VITE_SECRET_KEY': `"${process.env.VITE_SECRET_KEY}"`,
},
});
};
function renderChunks(deps: Record<string, string>) {
let chunks = {};
for (const key in deps) {
if (!['react', 'react-router-dom', 'react-dom'].includes(key)) {
chunks[key] = [key];
}
}
return chunks;
}