1
1
import path from "path" ;
2
- import type { UserConfig } from "vite" ;
2
+ import { UserConfig } from "vite" ;
3
3
import vue from "@vitejs/plugin-vue" ;
4
4
import vueJsx from "@vitejs/plugin-vue-jsx" ;
5
5
import viteCompression from "vite-plugin-compression" ;
@@ -13,6 +13,21 @@ function resolve(dir: string) {
13
13
// https://vitejs.dev/config/
14
14
15
15
export default ( ) : UserConfig => {
16
+ // 请求代理地址
17
+ const proxy = {
18
+ "/dev" : {
19
+ target : "http://127.0.0.1:8001" ,
20
+ changeOrigin : true ,
21
+ rewrite : ( path : string ) => path . replace ( / ^ \/ d e v / , "" )
22
+ } ,
23
+
24
+ "/pro" : {
25
+ target : "https://show.cool-admin.com" ,
26
+ changeOrigin : true ,
27
+ rewrite : ( path : string ) => path . replace ( / ^ \/ p r o / , "/api" )
28
+ }
29
+ } ;
30
+
16
31
return {
17
32
base : "/" ,
18
33
plugins : [ vue ( ) , viteCompression ( ) , Components ( ) , vueJsx ( ) , svgBuilder ( "./src/icons/svg/" ) ] ,
@@ -32,23 +47,14 @@ export default (): UserConfig => {
32
47
} ,
33
48
server : {
34
49
port : 9000 ,
50
+ proxy,
35
51
hmr : {
36
52
overlay : true
37
- } ,
38
- proxy : {
39
- "/dev" : {
40
- target : "http://127.0.0.1:8001" ,
41
- changeOrigin : true ,
42
- rewrite : ( path ) => path . replace ( / ^ \/ d e v / , "" )
43
- } ,
44
-
45
- "/pro" : {
46
- target : "https://show.cool-admin.com" ,
47
- changeOrigin : true ,
48
- rewrite : ( path ) => path . replace ( / ^ \/ p r o / , "/api" )
49
- }
50
53
}
51
54
} ,
55
+ define : {
56
+ __PROXY_LIST__ : JSON . stringify ( proxy )
57
+ } ,
52
58
build : {
53
59
sourcemap : false ,
54
60
polyfillDynamicImport : false // 必须为false
0 commit comments