-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvite.config.ts
72 lines (66 loc) · 1.59 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
/// <reference types="vitest" />
import legacy from '@vitejs/plugin-legacy';
import react from '@vitejs/plugin-react';
import path from 'path';
import { visualizer } from 'rollup-plugin-visualizer';
import type { AliasOptions, UserConfigExport } from 'vite';
import { defineConfig } from 'vite';
const ReactCompilerConfig = {
sources: (filename: string) => {
return filename.indexOf('src/') !== -1;
},
};
const AliasConfig: AliasOptions = {
'~/': `${path.resolve(__dirname, 'src')}/`,
};
export default defineConfig(({ mode }) => {
const options: UserConfigExport = {
resolve: {
alias: AliasConfig,
},
plugins: [
react({
babel: {
plugins: [['babel-plugin-react-compiler', ReactCompilerConfig]],
},
}),
...(mode === 'production'
? [
legacy({
targets: ['chrome >= 87', 'edge >= 88', 'firefox >= 78', 'safari >= 14'],
modernPolyfills: true,
}),
visualizer({
open: false,
}),
]
: []),
],
test: {
environment: 'happy-dom',
alias: AliasConfig,
},
};
if (mode === 'production') {
options.esbuild = {
drop: ['console', 'debugger'],
};
options.build = {
minify: 'esbuild',
rollupOptions: {
output: {
manualChunks(id) {
if (id.includes('react')) {
return 'react-vendor';
}
},
},
},
cssTarget: 'chrome61',
modulePreload: {
polyfill: true,
},
};
}
return options;
});