fix: [H5]:运行环境判断错误

This commit is contained in:
h_mo 2023-03-28 23:16:31 +08:00
parent 5710ae16ee
commit 0b3f5601c8
4 changed files with 7 additions and 12 deletions

View File

@ -1,6 +1,5 @@
# 运行环境
VITE_PROD = false
VITE_DEV = true
VITE_ENV = development
VITE_PORT = 3000

View File

@ -1,6 +1,5 @@
# 运行环境
VITE_PROD = true
VITE_DEV = false
VITE_ENV = production
# api域名
VITE_BASE_URL = https://api-catch.ranesuangyu.top

2
src/types/env.d.ts vendored
View File

@ -12,8 +12,6 @@ interface ImportMetaEnv {
readonly VITE_APP_TITLE: string;
readonly VITE_BASE_URL: string;
readonly VITE_UPLOAD_URL: string;
readonly VITE_PROD: boolean;
readonly VITE_DEV: boolean;
readonly VITE_APP_CACHE_PREFIX: string;
readonly VITE_PORT: number;
}

View File

@ -25,7 +25,7 @@ export const prodMode = 'production';
* @example:
*/
export function getEnvMode(): string {
return isDevMode() ? devMode : prodMode;
return getEnvValue('VITE_ENV');
}
/**
@ -33,9 +33,8 @@ export function getEnvMode(): string {
* @returns:
* @example:
*/
export function getEnvValue<T = any>(key: string): T {
// @ts-ignore
return import.meta.env[key];
export function getEnvValue<T = string>(key: keyof ImportMetaEnv): T {
return import.meta.env[key] as unknown as T;
}
/**
@ -44,7 +43,7 @@ export function getEnvValue<T = any>(key: string): T {
* @example:
*/
export function isDevMode(): boolean {
return getEnvValue<boolean>('VITE_DEV');
return getEnvMode() === devMode;
}
/**
@ -53,7 +52,7 @@ export function isDevMode(): boolean {
* @example:
*/
export function isProdMode(): boolean {
return getEnvValue<boolean>('VITE_PROD');
return getEnvMode() === prodMode;
}
/**