This repository has been archived on 2025-11-04. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
ndm-web-client-r/vite.config.ts
2025-08-04 14:10:35 +08:00

42 lines
1.0 KiB
TypeScript

import type { ProxyOptions } from 'vite';
import { tanstackRouter } from '@tanstack/router-plugin/vite';
import react from '@vitejs/plugin-react';
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(),
],
server: {
port: 9763,
proxy: viteProxy,
},
};
});