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