48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
import type { ProxyOptions } from 'vite';
|
|
|
|
import { tanstackRouter } from '@tanstack/router-plugin/vite';
|
|
import react from '@vitejs/plugin-react';
|
|
import { fileURLToPath, URL } from 'node:url';
|
|
import { defineConfig } from 'vite';
|
|
|
|
const apiProxyList: [string, string][] = [
|
|
['/api', 'http://172.16.6.248: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: [
|
|
tanstackRouter({
|
|
target: 'react',
|
|
autoCodeSplitting: true,
|
|
}),
|
|
react(),
|
|
],
|
|
resolve: {
|
|
alias: {
|
|
'@': fileURLToPath(new URL('./src', import.meta.url)),
|
|
},
|
|
},
|
|
server: {
|
|
port: 9763,
|
|
proxy: viteProxy,
|
|
},
|
|
};
|
|
});
|