vite.config.ts 1.26 KB
import react from '@vitejs/plugin-react';
import { fileURLToPath, URL } from 'node:url';
import { loadEnv } from 'vite';
import { defineConfig } from 'vitest/config';

// const DEFAULT_PROXY_TARGET = 'http://192.168.1.191:8000';
const DEFAULT_PROXY_TARGET = 'http://agent-admin.test.glsx.com.cn/backend';

export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd(), '');
  const proxyTarget = env.VITE_API_PROXY_TARGET || DEFAULT_PROXY_TARGET;

  return {
    plugins: [react()],
    resolve: {
      alias: {
        '@gl/business-components': fileURLToPath(new URL('../../../packages/business-components/src/index.ts', import.meta.url)),
        react: fileURLToPath(new URL('./node_modules/react', import.meta.url)),
        'tdesign-icons-react': fileURLToPath(new URL('./node_modules/tdesign-icons-react', import.meta.url)),
        'tdesign-react': fileURLToPath(new URL('./node_modules/tdesign-react', import.meta.url)),
      },
    },
    server: {
      host: '0.0.0.0',
      proxy: {
        '/api': {
          target: proxyTarget,
          changeOrigin: true,
        },
      },
    },
    preview: {
      host: '0.0.0.0',
    },
    test: {
      environment: 'jsdom',
      globals: true,
      setupFiles: './src/test/setup.ts',
    },
  };
});