import {
  defaultImportmapOptions,
  defineConfig,
  getDefaultPwaOptions,
  loadAndConvertEnv,
} from '@vben/vite-config';

export default defineConfig(async () => {
  const { appTitle, base, port, ...envConfig } = await loadAndConvertEnv();
  return {
    application: {
      ...envConfig,
      importmap: false,
      importmapOptions: defaultImportmapOptions,
      pwa: false,
      pwaOptions: getDefaultPwaOptions(appTitle),
    },
    vite: {
      base,
      server: {
        port,
        proxy: {
          '/api': {
            changeOrigin: true,
            rewrite: (path) => path.replace(/^\/api/, ''),
            // mock代理目标地址
            target: 'http://localhost:5320/api',
            ws: true,
          },
        },
      },
    },
  };
});
