chore: utils
This commit is contained in:
@@ -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,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user