Vben
authored
|
1
|
import type { GlobEnvConfig } from '/#/config';
|
nebv
authored
|
2
|
|
Vben
authored
|
3
|
import pkg from '../../package.json';
|
vben
authored
|
4
5
|
const getVariableName = (title: string) => {
|
vben
authored
|
6
7
8
|
return `__PRODUCTION__${title.replace(/\s/g, '_') || '__APP'}__CONF__`
.toUpperCase()
.replace(/\s/g, '');
|
vben
authored
|
9
|
};
|
Vben
authored
|
10
|
|
Vben
authored
|
11
|
export function getCommonStoragePrefix() {
|
vben
authored
|
12
13
|
const { VITE_GLOB_APP_TITLE } = getAppEnvConfig();
return `${VITE_GLOB_APP_TITLE.replace(/\s/g, '_')}__${getEnv()}`.toUpperCase();
|
vben
authored
|
14
|
}
|
nebv
authored
|
15
|
|
Vben
authored
|
16
17
|
// Generate cache key according to version
export function getStorageShortName() {
|
Vben
authored
|
18
19
20
21
|
return `${getCommonStoragePrefix()}${`__${pkg.version}`}__`.toUpperCase();
}
export function getAppEnvConfig() {
|
vben
authored
|
22
|
const ENV_NAME = getVariableName(import.meta.env.VITE_GLOB_APP_TITLE);
|
Vben
authored
|
23
|
|
Vben
authored
|
24
|
const ENV = (import.meta.env.DEV
|
Vben
authored
|
25
|
? // Get the global configuration (the configuration will be extracted independently when packaging)
|
Vben
authored
|
26
27
|
(import.meta.env as unknown as GlobEnvConfig)
: window[ENV_NAME as any]) as unknown as GlobEnvConfig;
|
Vben
authored
|
28
|
|
vben
authored
|
29
30
|
const { VITE_GLOB_APP_TITLE, VITE_GLOB_API_URL, VITE_GLOB_API_URL_PREFIX, VITE_GLOB_UPLOAD_URL } =
ENV;
|
Vben
authored
|
31
|
|
Vben
authored
|
32
33
34
35
36
37
|
return {
VITE_GLOB_APP_TITLE,
VITE_GLOB_API_URL,
VITE_GLOB_API_URL_PREFIX,
VITE_GLOB_UPLOAD_URL,
};
|
Vben
authored
|
38
39
|
}
|
|
40
|
/**
|
|
41
|
* @description: Development mode
|
|
42
43
44
45
|
*/
export const devMode = 'development';
/**
|
vben
authored
|
46
|
* @description: Production mode
|
|
47
48
49
50
|
*/
export const prodMode = 'production';
/**
|
vben
authored
|
51
|
* @description: Get environment variables
|
|
52
53
54
|
* @returns:
* @example:
*/
|
vben
authored
|
55
56
57
|
export function getEnv(): string {
return import.meta.env.MODE;
}
|
|
58
59
|
/**
|
vben
authored
|
60
|
* @description: Is it a development mode
|
|
61
62
63
|
* @returns:
* @example:
*/
|
vben
authored
|
64
65
66
|
export function isDevMode(): boolean {
return import.meta.env.DEV;
}
|
|
67
68
|
/**
|
vben
authored
|
69
|
* @description: Is it a production mode
|
|
70
71
72
|
* @returns:
* @example:
*/
|
vben
authored
|
73
74
75
|
export function isProdMode(): boolean {
return import.meta.env.PROD;
}
|