chore: utils

This commit is contained in:
2025-08-04 14:10:35 +08:00
parent ff657f29d4
commit 9a45304dd9
7 changed files with 622 additions and 12 deletions

View File

@@ -1,17 +1,41 @@
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({
plugins: [
tanstackRouter({
target: 'react',
autoCodeSplitting: true,
}),
react(),
],
server: {
port: 9763,
},
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,
},
};
});