| | |
| | | import type { GlobEnvConfig } from '/@/types/config'; |
| | | import type { GlobEnvConfig } from '/#/config'; |
| | | |
| | | export function getGlobEnvConfig(): GlobEnvConfig { |
| | | const env = import.meta.env; |
| | | return (env as unknown) as GlobEnvConfig; |
| | | import { warn } from '/@/utils/log'; |
| | | import pkg from '../../package.json'; |
| | | import { getConfigFileName } from '../../build/getConfigFileName'; |
| | | |
| | | export function getCommonStoragePrefix() { |
| | | const { VITE_GLOB_APP_SHORT_NAME } = getAppEnvConfig(); |
| | | return `${VITE_GLOB_APP_SHORT_NAME}__${getEnv()}`.toUpperCase(); |
| | | } |
| | | |
| | | // Generate cache key according to version |
| | | export function getStorageShortName() { |
| | | return `${getCommonStoragePrefix()}${`__${pkg.version}`}__`.toUpperCase(); |
| | | } |
| | | |
| | | export function getAppEnvConfig() { |
| | | const ENV_NAME = getConfigFileName(import.meta.env); |
| | | |
| | | const ENV = ((import.meta.env.DEV |
| | | ? // Get the global configuration (the configuration will be extracted independently when packaging) |
| | | ((import.meta.env as unknown) as GlobEnvConfig) |
| | | : window[ENV_NAME as any]) as unknown) as GlobEnvConfig; |
| | | |
| | | const { |
| | | VITE_GLOB_APP_TITLE, |
| | | VITE_GLOB_API_URL, |
| | | VITE_GLOB_APP_SHORT_NAME, |
| | | VITE_GLOB_API_URL_PREFIX, |
| | | VITE_GLOB_UPLOAD_URL, |
| | | } = ENV; |
| | | |
| | | if (!/[a-zA-Z\_]*/.test(VITE_GLOB_APP_SHORT_NAME)) { |
| | | warn( |
| | | `VITE_GLOB_APP_SHORT_NAME Variables can only be characters/underscores, please modify in the environment variables and re-running.` |
| | | ); |
| | | } |
| | | return { |
| | | VITE_GLOB_APP_TITLE, |
| | | VITE_GLOB_API_URL, |
| | | VITE_GLOB_APP_SHORT_NAME, |
| | | VITE_GLOB_API_URL_PREFIX, |
| | | VITE_GLOB_UPLOAD_URL, |
| | | }; |
| | | } |
| | | |
| | | /** |
| | | * @description: 开发模式 |
| | | * @description: Development model |
| | | */ |
| | | export const devMode = 'development'; |
| | | |
| | | /** |
| | | * @description: 生产模式 |
| | | * @description: Production mode |
| | | */ |
| | | export const prodMode = 'production'; |
| | | |
| | | /** |
| | | * @description: 获取环境变量 |
| | | * @description: Get environment variables |
| | | * @returns: |
| | | * @example: |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * @description: 是否是开发模式 |
| | | * @description: Is it a development mode |
| | | * @returns: |
| | | * @example: |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * @description: 是否是生产模式模式 |
| | | * @description: Is it a production mode |
| | | * @returns: |
| | | * @example: |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * @description: 是否开启mock |
| | | * @description: Whether to open mock |
| | | * @returns: |
| | | * @example: |
| | | */ |