mirror of
https://gitee.com/h_mo/uniapp-vue3-vite-ts-template
synced 2025-04-05 06:12:44 +08:00
54 lines
991 B
TypeScript
54 lines
991 B
TypeScript
import pkg from '../../package.json';
|
|
|
|
// Generate cache key according to version
|
|
export function getPkgVersion() {
|
|
return `${`__${pkg.version}`}__`.toUpperCase();
|
|
}
|
|
|
|
/**
|
|
* @description: Development mode
|
|
*/
|
|
export const devMode = 'development';
|
|
|
|
/**
|
|
* @description: Production mode
|
|
*/
|
|
export const prodMode = 'production';
|
|
|
|
/**
|
|
* @description: Get environment mode
|
|
* @returns:
|
|
* @example:
|
|
*/
|
|
export function getEnvMode(): string {
|
|
return isDevMode() ? devMode : prodMode;
|
|
}
|
|
|
|
/**
|
|
* @description: Get environment variables
|
|
* @returns:
|
|
* @example:
|
|
*/
|
|
export function getEnvValue<T = any>(key: string): T {
|
|
// @ts-ignore
|
|
return import.meta.env[key];
|
|
}
|
|
|
|
/**
|
|
* @description: Is it a development mode
|
|
* @returns:
|
|
* @example:
|
|
*/
|
|
export function isDevMode(): boolean {
|
|
return getEnvValue<boolean>('VITE_DEV');
|
|
}
|
|
|
|
/**
|
|
* @description: Is it a production mode
|
|
* @returns:
|
|
* @example:
|
|
*/
|
|
export function isProdMode(): boolean {
|
|
return getEnvValue<boolean>('VITE_PROD');
|
|
}
|