-
Notifications
You must be signed in to change notification settings - Fork 7
/
vite.config.ts
131 lines (120 loc) · 3.25 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
130
131
// @ts-nocheck
import { defineConfig } from 'vite';
import { chunkSplitPlugin } from 'vite-plugin-chunk-split';
import viteImagemin from 'vite-plugin-imagemin';
import mkcert from 'vite-plugin-mkcert';
import svgr from 'vite-plugin-svgr';
import { resolve } from 'path';
import { visualizer } from 'rollup-plugin-visualizer';
import Unocss from 'unocss/vite';
import legacy from '@vitejs/plugin-legacy';
import react from '@vitejs/plugin-react';
const shouldAnalyze = process.env.ANALYZE ?? false;
const isHttps = process.env.HTTPS ?? false;
// https://vitejs.dev/config/
export default defineConfig((config: ConfigEnv) => {
return {
plugins: [
react({
// Removes React Devtools in production build
removeDevtoolsInProd: true,
// Exclude storybook stories
exclude: /\.stories\.(t|j)sx?$/,
}),
// legacy(),
svgr(),
mkcert({
source: 'coding',
}),
// https://github.com/antfu/unocss
// see unocss.config.ts for config
Unocss(),
viteImagemin({
disable: config.mode === 'development',
mozjpeg: {
progressive: true,
quality: 80,
},
optipng: {
optimizationLevel: 3,
},
pngquant: {
quality: [0.8, 0.9],
speed: 7,
},
webp: {
quality: 80,
},
gifsicle: {
optimizationLevel: 8,
interlaced: false,
},
}),
chunkSplitPlugin({
strategy: 'all-in-one',
customSplitting: {
'react-vendor': ['react', 'react-dom', 'react-router-dom'],
},
}),
],
build: {
target: 'es2018',
rollupOptions: {
plugins: !!shouldAnalyze ? [visualizer({ filename: './dist/_stats.html' })] : [],
},
sourcemap: !!shouldAnalyze,
},
css: {
devSourcemap: true,
preprocessorOptions: {
less: {
javascriptEnabled: true,
},
sass: {
javascriptEnabled: true,
},
},
},
cacheDir: './.vite-cache',
/**
* defining aliases
*/
resolve: {
alias: {
'~src': resolve(__dirname, 'src'),
'~components': resolve(__dirname, 'src', 'components'),
'~hooks': resolve(__dirname, 'src', 'hooks'),
'~api': resolve(__dirname, 'src', 'api'),
'~store': resolve(__dirname, 'src', 'store'),
'~images': resolve(__dirname, 'src', 'assets', 'images'),
'~styles': resolve(__dirname, 'src', 'assets', 'styles'),
'~fonts': resolve(__dirname, 'src', 'assets', 'fonts'),
'~utils': resolve(__dirname, 'src', 'utils'),
'~pages': resolve(__dirname, 'src', 'pages'),
'~constants': resolve(__dirname, 'src', 'constants'),
'~containers': resolve(__dirname, 'src', 'containers'),
'~types': resolve(__dirname, 'src', 'types'),
'~sections': resolve(__dirname, 'src', 'sections'),
},
},
envDir: resolve(__dirname, 'src', 'env'),
envPrefix: 'GB_',
server: {
https: !!isHttps,
proxy: {
/**
* When we use proxy API requests, we can get data from an external website that throws an error by default (if we don't use a proxy)
* https://localhost:3000/api/** -> https://jsonplaceholder.typicode.com/**
*
* @example
* https://localhost:3000/api/todos/1 -> https://jsonplaceholder.typicode.com/todos/1
**/
'/api/': {
target: 'https://jsonplaceholder.typicode.com/',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ''),
},
},
},
};
});