admin-vben/packages/effects/hooks/src/use-app-config.ts

25 lines
598 B
TypeScript
Raw Normal View History

import type {
ApplicationConfig,
VbenAdminProAppConfigRaw,
} from '@vben/types/global';
/**
* vite-inject-app-config
*/
export function useAppConfig(
env: Record<string, any>,
isProduction: boolean,
): ApplicationConfig {
// 生产环境下,直接使用 window._VBEN_ADMIN_PRO_APP_CONF_ 全局变量
const config = isProduction
? window._VBEN_ADMIN_PRO_APP_CONF_
: (env as VbenAdminProAppConfigRaw);
const { VITE_GLOB_API_URL, VITE_GLOB_APP_TITLE } = config;
return {
apiURL: VITE_GLOB_API_URL,
appTitle: VITE_GLOB_APP_TITLE,
};
}