49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
import { fileURLToPath, URL } from 'node:url';
|
|
|
|
import { defineConfig, ProxyOptions } from 'vite';
|
|
import vue from '@vitejs/plugin-vue';
|
|
import vueJsx from '@vitejs/plugin-vue-jsx';
|
|
import vueDevTools from 'vite-plugin-vue-devtools';
|
|
|
|
const apiProxyList: [string, string][] = [
|
|
['/minio', 'http://172.16.6.248:9002'],
|
|
// ['/api', 'http://172.16.6.248:18760/api'],
|
|
// ['/api', 'http://localhost:3000/api'],
|
|
// ['/10/api', 'http://localhost:3000/api'],
|
|
// ['/11/api', 'http://localhost:3000/api'],
|
|
['/api', 'http://172.16.6.113:18760/api'],
|
|
['/113/api', 'http://172.16.6.113:18760/api'],
|
|
['/114/api', 'http://172.16.6.114:18760/api'],
|
|
];
|
|
|
|
// https://vite.dev/config/
|
|
export default defineConfig((/* { command, mode } */) => {
|
|
const viteProxy: Record<string, string | ProxyOptions> = {};
|
|
apiProxyList.forEach((apiProxy) => {
|
|
const [prefix, target] = apiProxy;
|
|
viteProxy[prefix] = {
|
|
target,
|
|
changeOrigin: true,
|
|
rewrite: (path) => {
|
|
console.log(`请求路径: ${path}`);
|
|
const rewrittenPath = path.replace(new RegExp(`^${prefix}`), '');
|
|
console.log(`将代理到: ${target}${rewrittenPath}`);
|
|
return rewrittenPath;
|
|
},
|
|
};
|
|
});
|
|
|
|
return {
|
|
plugins: [vue(), vueJsx(), vueDevTools()],
|
|
resolve: {
|
|
alias: {
|
|
'@': fileURLToPath(new URL('./src', import.meta.url)),
|
|
},
|
|
},
|
|
server: {
|
|
port: 9654,
|
|
proxy: viteProxy,
|
|
},
|
|
};
|
|
});
|