# vite 别名配置需要2点
- Vite config
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import * as path from 'path'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
react()
],
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
server: {
port: 3000,
proxy: {
'/api': {
target: 'http://xuanyuan.jinuo.fun:8080/',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, '')
}
}
},
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
- Tsconfig.json
告诉TS解析如何解析某些路径
注意./src/* 后边这个*
一定要加