wsj
2026-10-17 bc1e862b8a487589dae756e3e1c5a5644c7986f5
vite.config.ts
@@ -1,8 +1,14 @@
import { fileURLToPath, URL } from 'node:url';
import react from '@vitejs/plugin-react';
import { defineConfig } from 'vite';
import { defineConfig, loadEnv } from 'vite';
export default defineConfig({
/** 开发环境通过 Vite 代理访问后端,避免浏览器跨域。 */
export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd(), '');
  const proxyTarget =
    env.VITE_API_PROXY_TARGET || env.VITE_API_BASE_URL || 'http://localhost:9090';
  return {
  plugins: [react()],
  resolve: {
    alias: {
@@ -12,5 +18,13 @@
  server: {
    port: 5173,
    host: true,
      proxy: {
        '/proxy-api': {
          target: proxyTarget,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/proxy-api/, ''),
  },
      },
    },
  };
});