-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
104 lines (92 loc) · 2.26 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
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx';
import { resolve } from 'path';
const currentEnv = process.env.currentEnv || "";
console.log("currentEnv ", currentEnv, getPrefixUrl(currentEnv));
function getPrefixUrl(currentEnv: string) {
let url = "";
switch (currentEnv) {
case "dev":
url = "http://dev-data.lbxcn.com";
break;
case "qa":
url = 'http://qa-data.lbxcn.com';
break;
case "release":
url = "http://release-data.lbxcn.com";
break;
case "prod":
url = "http://data.lbxcn.com";
break;
// native local develop
default:
url = "http://localhost:5173"
}
return url
}
const list: any[] = [
// {
// path: '/api',
// target: 'http://localhost:8900',
// }
{
path: '/api',
target: "http://debug-data.lbxcn.com",
// target: 'http://10.0.208.146:9700',
// target: "http://dev-data.lbxcn.com"
}
];
const proxyOption = {
changeOrigin: true,
debug: true,
};
function proxy() {
const result = list
.map((item) => ({
[item.path]: {
...proxyOption,
target: item.target,
rewrite: (pathname: string) => {
console.log('pathname: ', item.path, item.target + pathname.replace(item.path, '/api'));
return pathname.replace(item.path, '/api');
},
},
}))
.reduce((previous, current) => ({ ...previous, ...current }), {});
console.log(JSON.stringify(result, null, 2));
return result;
};
function pathResolve(dir: string) {
return resolve(process.cwd(), '.', dir);
}
// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue(), vueJsx()],
define: {
'process.env': {
prefixUrl: getPrefixUrl(currentEnv),
currentEnv,
},
},
resolve: {
alias: [
{
find: /\/#\//,
replacement: pathResolve('types') + '/',
},
{
find: '@',
replacement: pathResolve('src') + '/',
},
{
find: 'vue',
replacement: 'vue/dist/vue.esm-bundler.js', // compile template
},
],
},
server: {
// open: true,
proxy: proxy(),
},
})