Blame view

src/utils/env.ts 1.33 KB
Vben authored
1
import type { GlobEnvConfig } from '/#/config';
2
Vben authored
3
4
5
import { useGlobSetting } from '/@/hooks/setting';
import pkg from '../../package.json';
vben authored
6
7
8
/**
 * Get the global configuration (the configuration will be extracted independently when packaging)
 */
9
export function getGlobEnvConfig(): GlobEnvConfig {
10
11
  const env = import.meta.env;
  return (env as unknown) as GlobEnvConfig;
12
}
13
Vben authored
14
15
16
17
18
19
// Generate cache key according to version
export function getStorageShortName() {
  const globSetting = useGlobSetting();
  return `${globSetting.shortName}__${getEnv()}${`__${pkg.version}`}__`.toUpperCase();
}
陈文彬 authored
20
/**
vben authored
21
 * @description: Development model
陈文彬 authored
22
23
24
25
 */
export const devMode = 'development';

/**
vben authored
26
 * @description: Production mode
陈文彬 authored
27
28
29
30
 */
export const prodMode = 'production';

/**
vben authored
31
 * @description: Get environment variables
陈文彬 authored
32
33
34
 * @returns:
 * @example:
 */
35
36
37
export function getEnv(): string {
  return import.meta.env.MODE;
}
陈文彬 authored
38
39

/**
vben authored
40
 * @description: Is it a development mode
陈文彬 authored
41
42
43
 * @returns:
 * @example:
 */
44
45
46
export function isDevMode(): boolean {
  return import.meta.env.DEV;
}
陈文彬 authored
47
48

/**
vben authored
49
 * @description: Is it a production mode
陈文彬 authored
50
51
52
 * @returns:
 * @example:
 */
53
54
55
export function isProdMode(): boolean {
  return import.meta.env.PROD;
}
陈文彬 authored
56
57

/**
vben authored
58
 * @description: Whether to open mock
陈文彬 authored
59
60
61
 * @returns:
 * @example:
 */
62
63
64
export function isUseMock(): boolean {
  return import.meta.env.VITE_USE_MOCK === 'true';
}