use-app-config.ts 542 B

1234567891011121314151617181920212223
  1. import type {
  2. ApplicationConfig,
  3. VbenAdminProAppConfigRaw,
  4. } from '@vben/types/global';
  5. /**
  6. * 由 vite-inject-app-config 注入的全局配置
  7. */
  8. export function useAppConfig(
  9. env: Record<string, any>,
  10. isProduction: boolean,
  11. ): ApplicationConfig {
  12. // 生产环境下,直接使用 window._VBEN_ADMIN_PRO_APP_CONF_ 全局变量
  13. const config = isProduction
  14. ? window._VBEN_ADMIN_PRO_APP_CONF_
  15. : (env as VbenAdminProAppConfigRaw);
  16. const { VITE_GLOB_API_URL } = config;
  17. return {
  18. apiURL: VITE_GLOB_API_URL,
  19. };
  20. }