-
Notifications
You must be signed in to change notification settings - Fork 81
/
vite.config.ts
93 lines (89 loc) · 2.45 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
import react from '@vitejs/plugin-react'
import path from 'path'
import { defineConfig, loadEnv } from 'vite'
import { ViteEjsPlugin } from 'vite-plugin-ejs'
import svgrPlugin from 'vite-plugin-svgr'
import viteTsconfigPaths from 'vite-tsconfig-paths'
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '')
const buildTarget = env.VITE_BUILD_TARGET || 'web'
const buildPlatform = env.VITE_BUILD_PLATFORM
if (!env.VITE_API_URL) {
throw new Error('VITE_API_URL is not defined, create an .env file with this variable')
}
if (buildTarget == 'extension' && !buildPlatform) {
throw new Error('VITE_BUILD_PLATFORM is not defined, create an .env file with this variable')
}
return {
plugins: [
ViteEjsPlugin((viteConfig) => {
return {
isWebBuild: viteConfig.env.VITE_BUILD_TARGET === 'web',
}
}),
react(),
viteTsconfigPaths(),
svgrPlugin(),
],
define: {
'process.env': {},
},
build: {
emptyOutDir: true,
rollupOptions: {
output: {
entryFileNames: `assets/[name].js`,
chunkFileNames: `assets/[name]-[hash].js`,
assetFileNames: `assets/[name]-[hash].[ext]`,
manualChunks: {
core: [
'react',
'react-dom',
'react-router-dom',
'zustand',
'@tanstack/react-query',
'@tanstack/react-query-persist-client',
'axios',
'react-error-boundary',
],
ui: [
'react-contexify',
'react-select',
'react-share',
'react-simple-toasts',
'react-toggle',
'react-tooltip',
'react-icons',
'react-markdown',
'react-spring-bottom-sheet',
],
utils: [
'@amplitude/analytics-browser',
'axios-cache-adapter',
'country-emoji',
'htmlparser2',
'dompurify',
'timeago.js',
],
},
},
},
},
server: {
open: true,
proxy: {
'/api': {
target: env.VITE_API_URL,
changeOrigin: true,
secure: false,
rewrite: (path) => path.replace(/^\/api/, ''),
},
},
},
resolve: {
alias: {
src: path.resolve(__dirname, './src'),
},
},
}
})