-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
92 lines (88 loc) · 2.21 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
import { fileURLToPath, URL } from 'node:url'
import react from '@vitejs/plugin-react-swc'
import AutoImport from 'unplugin-auto-import/vite'
import Icons from 'unplugin-icons/vite'
import type { ProxyOptions } from 'vite'
import { defineConfig, loadEnv } from 'vite'
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd())
const { VITE_PORT, VITE_BASE_API_URL, VITE_MOCK_API_URL } = env as ImportMetaEnv
const port = parseInt(VITE_PORT, 10) || 5173
const proxy: Record<string, string | ProxyOptions> = {
'/base-api': {
target: VITE_BASE_API_URL,
changeOrigin: true,
rewrite: (path: string) => path.replace(/^\/base-api/, '')
},
'/mock-api': {
target: VITE_MOCK_API_URL,
changeOrigin: true,
rewrite: (path: string) => path.replace(/^\/mock-api/, '')
}
}
return {
base: '/',
plugins: [
react(),
AutoImport({
dts: '@types/auto-imports.d.ts',
include: [
/\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
/\.md$/ // .md
],
imports: [
'react',
'react-router-dom',
'ahooks',
{
from: '@tanstack/react-query',
imports: ['useQueryClient', 'useQuery', 'useMutation']
},
{
from: '@/constants',
imports: ['GlobalEnvConfig', 'BasePageModel', 'AppConfig']
}
],
dirs: [
'src/api',
'src/components',
'src/config',
'src/hooks',
'src/layouts',
'src/providers',
'src/store',
'src/tools',
'src/utils'
]
}),
Icons({
autoInstall: true,
compiler: 'jsx',
jsx: 'react'
})
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
},
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json']
},
esbuild: {
drop: mode === 'production' ? ['console', 'debugger'] : []
},
server: {
host: true,
port,
strictPort: true,
open: false,
proxy
},
preview: {
host: true,
port,
strictPort: true,
open: false,
proxy
}
}
})