Commit aedb8e53aa25660b6179389eda0a6b1937bb78fd

Authored by vben
1 parent 358b77fe

perf: 优化env字段

1 1 # spa-title
2 2 VITE_GLOB_APP_TITLE = Vben Admin
3   -
4   -# spa shortname
5   -VITE_GLOB_APP_SHORT_NAME = vue_vben_admin
... ...
internal/vite-config/package.json
... ... @@ -31,6 +31,7 @@
31 31 "stub": "pnpm unbuild --stub"
32 32 },
33 33 "dependencies": {
  34 + "@ant-design/colors": "^7.0.0",
34 35 "vite": "^4.3.0-beta.1"
35 36 },
36 37 "devDependencies": {
... ...
internal/vite-config/src/config/application.ts
... ... @@ -74,7 +74,7 @@ function defineApplicationConfig(defineOptions: DefineOptions = {}) {
74 74 output: {
75 75 manualChunks: {
76 76 vue: ['vue', 'pinia', 'vue-router'],
77   - antdv: ['ant-design-vue', '@ant-design/icons-vue'],
  77 + antd: ['ant-design-vue', '@ant-design/icons-vue'],
78 78 },
79 79 },
80 80 },
... ...
internal/vite-config/src/plugins/appConfig.ts
... ... @@ -26,7 +26,8 @@ async function createAppConfigPlugin({
26 26 return {
27 27 name: PLUGIN_NAME,
28 28 async configResolved(_config) {
29   - const appTitle = _config?.env?.VITE_GLOB_APP_SHORT_NAME ?? '';
  29 + let appTitle = _config?.env?.VITE_GLOB_APP_TITLE ?? '';
  30 + appTitle = appTitle.replace(/\s/g, '_');
30 31 publicPath = _config.base;
31 32 source = await getConfigSource(appTitle);
32 33 },
... ...
package.json
... ... @@ -66,13 +66,10 @@
66 66 }
67 67 },
68 68 "dependencies": {
69   - "@ant-design/colors": "^7.0.0",
70 69 "@ant-design/icons-vue": "^6.1.0",
71 70 "@iconify/iconify": "^3.1.0",
72 71 "@logicflow/core": "^1.2.1",
73 72 "@logicflow/extension": "^1.2.1",
74   - "@vue/runtime-core": "^3.2.47",
75   - "@vue/shared": "^3.2.47",
76 73 "@vueuse/core": "^9.13.0",
77 74 "@vueuse/shared": "^9.13.0",
78 75 "@zxcvbn-ts/core": "^2.2.1",
... ... @@ -111,6 +108,7 @@
111 108 },
112 109 "devDependencies": {
113 110 "@commitlint/cli": "^17.5.1",
  111 + "@commitlint/config-conventional": "^17.4.4",
114 112 "@iconify/json": "^2.2.45",
115 113 "@purge-icons/generated": "^0.9.0",
116 114 "@types/codemirror": "^5.60.7",
... ...
pnpm-lock.yaml
... ... @@ -4,9 +4,6 @@ importers:
4 4  
5 5 .:
6 6 dependencies:
7   - '@ant-design/colors':
8   - specifier: ^7.0.0
9   - version: 7.0.0
10 7 '@ant-design/icons-vue':
11 8 specifier: ^6.1.0
12 9 version: 6.1.0(vue@3.2.47)
... ... @@ -19,12 +16,6 @@ importers:
19 16 '@logicflow/extension':
20 17 specifier: ^1.2.1
21 18 version: 1.2.1
22   - '@vue/runtime-core':
23   - specifier: ^3.2.47
24   - version: 3.2.47
25   - '@vue/shared':
26   - specifier: ^3.2.47
27   - version: 3.2.47
28 19 '@vueuse/core':
29 20 specifier: ^9.13.0
30 21 version: 9.13.0(vue@3.2.47)
... ... @@ -134,6 +125,9 @@ importers:
134 125 '@commitlint/cli':
135 126 specifier: ^17.5.1
136 127 version: 17.5.1
  128 + '@commitlint/config-conventional':
  129 + specifier: ^17.4.4
  130 + version: 17.4.4
137 131 '@iconify/json':
138 132 specifier: ^2.2.45
139 133 version: 2.2.45
... ... @@ -378,6 +372,9 @@ importers:
378 372  
379 373 internal/vite-config:
380 374 dependencies:
  375 + '@ant-design/colors':
  376 + specifier: ^7.0.0
  377 + version: 7.0.0
381 378 vite:
382 379 specifier: ^4.3.0-beta.1
383 380 version: 4.3.0-beta.1(@types/node@18.15.11)(less@4.1.3)(sass@1.60.0)
... ... @@ -791,6 +788,13 @@ packages:
791 788 - '@swc/wasm'
792 789 dev: true
793 790  
  791 + /@commitlint/config-conventional@17.4.4:
  792 + resolution: {integrity: sha512-u6ztvxqzi6NuhrcEDR7a+z0yrh11elY66nRrQIpqsqW6sZmpxYkDLtpRH8jRML+mmxYQ8s4qqF06Q/IQx5aJeQ==}
  793 + engines: {node: '>=v14'}
  794 + dependencies:
  795 + conventional-changelog-conventionalcommits: 5.0.0
  796 + dev: true
  797 +
794 798 /@commitlint/config-validator@17.4.4:
795 799 resolution: {integrity: sha512-bi0+TstqMiqoBAQDvdEP4AFh0GaKyLFlPPEObgI29utoKEYoPQTvF0EYqIwYYLEoJYhj5GfMIhPHJkTJhagfeg==}
796 800 engines: {node: '>=v14'}
... ... @@ -3176,6 +3180,15 @@ packages:
3176 3180 q: 1.5.1
3177 3181 dev: true
3178 3182  
  3183 + /conventional-changelog-conventionalcommits@5.0.0:
  3184 + resolution: {integrity: sha512-lCDbA+ZqVFQGUj7h9QBKoIpLhl8iihkO0nCTyRNzuXtcd7ubODpYB04IFy31JloiJgG0Uovu8ot8oxRzn7Nwtw==}
  3185 + engines: {node: '>=10'}
  3186 + dependencies:
  3187 + compare-func: 2.0.0
  3188 + lodash: 4.17.21
  3189 + q: 1.5.1
  3190 + dev: true
  3191 +
3179 3192 /conventional-commits-parser@3.2.4:
3180 3193 resolution: {integrity: sha512-nK7sAtfi+QXbxHCYfhpZsfRtaitZLIA6889kFIouLvz6repszQDgxBu7wf2WbU+Dco7sAnNCJYERCwt54WPC2Q==}
3181 3194 engines: {node: '>=10'}
... ...
src/hooks/setting/index.ts
1 1 import type { GlobConfig } from '/#/config';
2 2  
3   -import { warn } from '/@/utils/log';
4 3 import { getAppEnvConfig } from '/@/utils/env';
5 4  
6 5 export const useGlobSetting = (): Readonly<GlobConfig> => {
7   - const {
8   - VITE_GLOB_APP_TITLE,
9   - VITE_GLOB_API_URL,
10   - VITE_GLOB_APP_SHORT_NAME,
11   - VITE_GLOB_API_URL_PREFIX,
12   - VITE_GLOB_UPLOAD_URL,
13   - } = getAppEnvConfig();
14   -
15   - if (!/[a-zA-Z_]*/.test(VITE_GLOB_APP_SHORT_NAME)) {
16   - warn(
17   - `VITE_GLOB_APP_SHORT_NAME Variables can only be characters/underscores, please modify in the environment variables and re-running.`,
18   - );
19   - }
  6 + const { VITE_GLOB_APP_TITLE, VITE_GLOB_API_URL, VITE_GLOB_API_URL_PREFIX, VITE_GLOB_UPLOAD_URL } =
  7 + getAppEnvConfig();
20 8  
21 9 // Take global configuration
22 10 const glob: Readonly<GlobConfig> = {
23 11 title: VITE_GLOB_APP_TITLE,
24 12 apiUrl: VITE_GLOB_API_URL,
25   - shortName: VITE_GLOB_APP_SHORT_NAME,
  13 + shortName: VITE_GLOB_APP_TITLE.replace(/\s/g, '_'),
26 14 urlPrefix: VITE_GLOB_API_URL_PREFIX,
27 15 uploadUrl: VITE_GLOB_UPLOAD_URL,
28 16 };
... ...
src/utils/env.ts
1 1 import type { GlobEnvConfig } from '/#/config';
2 2  
3   -import { warn } from '/@/utils/log';
4 3 import pkg from '../../package.json';
5 4  
6 5 const getVariableName = (title: string) => {
7   - return `__PRODUCTION__${title || '__APP'}__CONF__`.toUpperCase().replace(/\s/g, '');
  6 + return `__PRODUCTION__${title.replace(/\s/g, '_') || '__APP'}__CONF__`
  7 + .toUpperCase()
  8 + .replace(/\s/g, '');
8 9 };
9 10  
10 11 export function getCommonStoragePrefix() {
11   - const { VITE_GLOB_APP_SHORT_NAME } = getAppEnvConfig();
12   - return `${VITE_GLOB_APP_SHORT_NAME}__${getEnv()}`.toUpperCase();
  12 + const { VITE_GLOB_APP_TITLE } = getAppEnvConfig();
  13 + return `${VITE_GLOB_APP_TITLE.replace(/\s/g, '_')}__${getEnv()}`.toUpperCase();
13 14 }
14 15  
15 16 // Generate cache key according to version
... ... @@ -18,31 +19,19 @@ export function getStorageShortName() {
18 19 }
19 20  
20 21 export function getAppEnvConfig() {
21   - const ENV_NAME = getVariableName(import.meta.env.VITE_GLOB_APP_SHORT_NAME);
  22 + const ENV_NAME = getVariableName(import.meta.env.VITE_GLOB_APP_TITLE);
22 23  
23 24 const ENV = (import.meta.env.DEV
24 25 ? // Get the global configuration (the configuration will be extracted independently when packaging)
25 26 (import.meta.env as unknown as GlobEnvConfig)
26 27 : window[ENV_NAME as any]) as unknown as GlobEnvConfig;
27 28  
28   - const {
29   - VITE_GLOB_APP_TITLE,
30   - VITE_GLOB_API_URL,
31   - VITE_GLOB_APP_SHORT_NAME,
32   - VITE_GLOB_API_URL_PREFIX,
33   - VITE_GLOB_UPLOAD_URL,
34   - } = ENV;
35   -
36   - if (!/^[a-zA-Z_]*$/.test(VITE_GLOB_APP_SHORT_NAME)) {
37   - warn(
38   - `VITE_GLOB_APP_SHORT_NAME Variables can only be characters/underscores, please modify in the environment variables and re-running.`,
39   - );
40   - }
  29 + const { VITE_GLOB_APP_TITLE, VITE_GLOB_API_URL, VITE_GLOB_API_URL_PREFIX, VITE_GLOB_UPLOAD_URL } =
  30 + ENV;
41 31  
42 32 return {
43 33 VITE_GLOB_APP_TITLE,
44 34 VITE_GLOB_API_URL,
45   - VITE_GLOB_APP_SHORT_NAME,
46 35 VITE_GLOB_API_URL_PREFIX,
47 36 VITE_GLOB_UPLOAD_URL,
48 37 };
... ...
types/config.d.ts
... ... @@ -155,8 +155,6 @@ export interface GlobEnvConfig {
155 155 VITE_GLOB_API_URL: string;
156 156 // Service interface url prefix
157 157 VITE_GLOB_API_URL_PREFIX?: string;
158   - // Project abbreviation
159   - VITE_GLOB_APP_SHORT_NAME: string;
160 158 // Upload url
161 159 VITE_GLOB_UPLOAD_URL?: string;
162 160 }
... ...
types/global.d.ts
... ... @@ -61,7 +61,6 @@ declare global {
61 61 VITE_PUBLIC_PATH: string;
62 62 VITE_PROXY: [string, string][];
63 63 VITE_GLOB_APP_TITLE: string;
64   - VITE_GLOB_APP_SHORT_NAME: string;
65 64 VITE_BUILD_COMPRESS: 'gzip' | 'brotli' | 'none';
66 65 }
67 66  
... ...