Commit aedb8e53aa25660b6179389eda0a6b1937bb78fd
1 parent
358b77fe
perf: 优化env字段
Showing
10 changed files
with
38 additions
and
54 deletions
.env
internal/vite-config/package.json
@@ -31,6 +31,7 @@ | @@ -31,6 +31,7 @@ | ||
31 | "stub": "pnpm unbuild --stub" | 31 | "stub": "pnpm unbuild --stub" |
32 | }, | 32 | }, |
33 | "dependencies": { | 33 | "dependencies": { |
34 | + "@ant-design/colors": "^7.0.0", | ||
34 | "vite": "^4.3.0-beta.1" | 35 | "vite": "^4.3.0-beta.1" |
35 | }, | 36 | }, |
36 | "devDependencies": { | 37 | "devDependencies": { |
internal/vite-config/src/config/application.ts
@@ -74,7 +74,7 @@ function defineApplicationConfig(defineOptions: DefineOptions = {}) { | @@ -74,7 +74,7 @@ function defineApplicationConfig(defineOptions: DefineOptions = {}) { | ||
74 | output: { | 74 | output: { |
75 | manualChunks: { | 75 | manualChunks: { |
76 | vue: ['vue', 'pinia', 'vue-router'], | 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,7 +26,8 @@ async function createAppConfigPlugin({ | ||
26 | return { | 26 | return { |
27 | name: PLUGIN_NAME, | 27 | name: PLUGIN_NAME, |
28 | async configResolved(_config) { | 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 | publicPath = _config.base; | 31 | publicPath = _config.base; |
31 | source = await getConfigSource(appTitle); | 32 | source = await getConfigSource(appTitle); |
32 | }, | 33 | }, |
package.json
@@ -66,13 +66,10 @@ | @@ -66,13 +66,10 @@ | ||
66 | } | 66 | } |
67 | }, | 67 | }, |
68 | "dependencies": { | 68 | "dependencies": { |
69 | - "@ant-design/colors": "^7.0.0", | ||
70 | "@ant-design/icons-vue": "^6.1.0", | 69 | "@ant-design/icons-vue": "^6.1.0", |
71 | "@iconify/iconify": "^3.1.0", | 70 | "@iconify/iconify": "^3.1.0", |
72 | "@logicflow/core": "^1.2.1", | 71 | "@logicflow/core": "^1.2.1", |
73 | "@logicflow/extension": "^1.2.1", | 72 | "@logicflow/extension": "^1.2.1", |
74 | - "@vue/runtime-core": "^3.2.47", | ||
75 | - "@vue/shared": "^3.2.47", | ||
76 | "@vueuse/core": "^9.13.0", | 73 | "@vueuse/core": "^9.13.0", |
77 | "@vueuse/shared": "^9.13.0", | 74 | "@vueuse/shared": "^9.13.0", |
78 | "@zxcvbn-ts/core": "^2.2.1", | 75 | "@zxcvbn-ts/core": "^2.2.1", |
@@ -111,6 +108,7 @@ | @@ -111,6 +108,7 @@ | ||
111 | }, | 108 | }, |
112 | "devDependencies": { | 109 | "devDependencies": { |
113 | "@commitlint/cli": "^17.5.1", | 110 | "@commitlint/cli": "^17.5.1", |
111 | + "@commitlint/config-conventional": "^17.4.4", | ||
114 | "@iconify/json": "^2.2.45", | 112 | "@iconify/json": "^2.2.45", |
115 | "@purge-icons/generated": "^0.9.0", | 113 | "@purge-icons/generated": "^0.9.0", |
116 | "@types/codemirror": "^5.60.7", | 114 | "@types/codemirror": "^5.60.7", |
pnpm-lock.yaml
@@ -4,9 +4,6 @@ importers: | @@ -4,9 +4,6 @@ importers: | ||
4 | 4 | ||
5 | .: | 5 | .: |
6 | dependencies: | 6 | dependencies: |
7 | - '@ant-design/colors': | ||
8 | - specifier: ^7.0.0 | ||
9 | - version: 7.0.0 | ||
10 | '@ant-design/icons-vue': | 7 | '@ant-design/icons-vue': |
11 | specifier: ^6.1.0 | 8 | specifier: ^6.1.0 |
12 | version: 6.1.0(vue@3.2.47) | 9 | version: 6.1.0(vue@3.2.47) |
@@ -19,12 +16,6 @@ importers: | @@ -19,12 +16,6 @@ importers: | ||
19 | '@logicflow/extension': | 16 | '@logicflow/extension': |
20 | specifier: ^1.2.1 | 17 | specifier: ^1.2.1 |
21 | version: 1.2.1 | 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 | '@vueuse/core': | 19 | '@vueuse/core': |
29 | specifier: ^9.13.0 | 20 | specifier: ^9.13.0 |
30 | version: 9.13.0(vue@3.2.47) | 21 | version: 9.13.0(vue@3.2.47) |
@@ -134,6 +125,9 @@ importers: | @@ -134,6 +125,9 @@ importers: | ||
134 | '@commitlint/cli': | 125 | '@commitlint/cli': |
135 | specifier: ^17.5.1 | 126 | specifier: ^17.5.1 |
136 | version: 17.5.1 | 127 | version: 17.5.1 |
128 | + '@commitlint/config-conventional': | ||
129 | + specifier: ^17.4.4 | ||
130 | + version: 17.4.4 | ||
137 | '@iconify/json': | 131 | '@iconify/json': |
138 | specifier: ^2.2.45 | 132 | specifier: ^2.2.45 |
139 | version: 2.2.45 | 133 | version: 2.2.45 |
@@ -378,6 +372,9 @@ importers: | @@ -378,6 +372,9 @@ importers: | ||
378 | 372 | ||
379 | internal/vite-config: | 373 | internal/vite-config: |
380 | dependencies: | 374 | dependencies: |
375 | + '@ant-design/colors': | ||
376 | + specifier: ^7.0.0 | ||
377 | + version: 7.0.0 | ||
381 | vite: | 378 | vite: |
382 | specifier: ^4.3.0-beta.1 | 379 | specifier: ^4.3.0-beta.1 |
383 | version: 4.3.0-beta.1(@types/node@18.15.11)(less@4.1.3)(sass@1.60.0) | 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,6 +788,13 @@ packages: | ||
791 | - '@swc/wasm' | 788 | - '@swc/wasm' |
792 | dev: true | 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 | /@commitlint/config-validator@17.4.4: | 798 | /@commitlint/config-validator@17.4.4: |
795 | resolution: {integrity: sha512-bi0+TstqMiqoBAQDvdEP4AFh0GaKyLFlPPEObgI29utoKEYoPQTvF0EYqIwYYLEoJYhj5GfMIhPHJkTJhagfeg==} | 799 | resolution: {integrity: sha512-bi0+TstqMiqoBAQDvdEP4AFh0GaKyLFlPPEObgI29utoKEYoPQTvF0EYqIwYYLEoJYhj5GfMIhPHJkTJhagfeg==} |
796 | engines: {node: '>=v14'} | 800 | engines: {node: '>=v14'} |
@@ -3176,6 +3180,15 @@ packages: | @@ -3176,6 +3180,15 @@ packages: | ||
3176 | q: 1.5.1 | 3180 | q: 1.5.1 |
3177 | dev: true | 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 | /conventional-commits-parser@3.2.4: | 3192 | /conventional-commits-parser@3.2.4: |
3180 | resolution: {integrity: sha512-nK7sAtfi+QXbxHCYfhpZsfRtaitZLIA6889kFIouLvz6repszQDgxBu7wf2WbU+Dco7sAnNCJYERCwt54WPC2Q==} | 3193 | resolution: {integrity: sha512-nK7sAtfi+QXbxHCYfhpZsfRtaitZLIA6889kFIouLvz6repszQDgxBu7wf2WbU+Dco7sAnNCJYERCwt54WPC2Q==} |
3181 | engines: {node: '>=10'} | 3194 | engines: {node: '>=10'} |
src/hooks/setting/index.ts
1 | import type { GlobConfig } from '/#/config'; | 1 | import type { GlobConfig } from '/#/config'; |
2 | 2 | ||
3 | -import { warn } from '/@/utils/log'; | ||
4 | import { getAppEnvConfig } from '/@/utils/env'; | 3 | import { getAppEnvConfig } from '/@/utils/env'; |
5 | 4 | ||
6 | export const useGlobSetting = (): Readonly<GlobConfig> => { | 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 | // Take global configuration | 9 | // Take global configuration |
22 | const glob: Readonly<GlobConfig> = { | 10 | const glob: Readonly<GlobConfig> = { |
23 | title: VITE_GLOB_APP_TITLE, | 11 | title: VITE_GLOB_APP_TITLE, |
24 | apiUrl: VITE_GLOB_API_URL, | 12 | apiUrl: VITE_GLOB_API_URL, |
25 | - shortName: VITE_GLOB_APP_SHORT_NAME, | 13 | + shortName: VITE_GLOB_APP_TITLE.replace(/\s/g, '_'), |
26 | urlPrefix: VITE_GLOB_API_URL_PREFIX, | 14 | urlPrefix: VITE_GLOB_API_URL_PREFIX, |
27 | uploadUrl: VITE_GLOB_UPLOAD_URL, | 15 | uploadUrl: VITE_GLOB_UPLOAD_URL, |
28 | }; | 16 | }; |
src/utils/env.ts
1 | import type { GlobEnvConfig } from '/#/config'; | 1 | import type { GlobEnvConfig } from '/#/config'; |
2 | 2 | ||
3 | -import { warn } from '/@/utils/log'; | ||
4 | import pkg from '../../package.json'; | 3 | import pkg from '../../package.json'; |
5 | 4 | ||
6 | const getVariableName = (title: string) => { | 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 | export function getCommonStoragePrefix() { | 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 | // Generate cache key according to version | 16 | // Generate cache key according to version |
@@ -18,31 +19,19 @@ export function getStorageShortName() { | @@ -18,31 +19,19 @@ export function getStorageShortName() { | ||
18 | } | 19 | } |
19 | 20 | ||
20 | export function getAppEnvConfig() { | 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 | const ENV = (import.meta.env.DEV | 24 | const ENV = (import.meta.env.DEV |
24 | ? // Get the global configuration (the configuration will be extracted independently when packaging) | 25 | ? // Get the global configuration (the configuration will be extracted independently when packaging) |
25 | (import.meta.env as unknown as GlobEnvConfig) | 26 | (import.meta.env as unknown as GlobEnvConfig) |
26 | : window[ENV_NAME as any]) as unknown as GlobEnvConfig; | 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 | return { | 32 | return { |
43 | VITE_GLOB_APP_TITLE, | 33 | VITE_GLOB_APP_TITLE, |
44 | VITE_GLOB_API_URL, | 34 | VITE_GLOB_API_URL, |
45 | - VITE_GLOB_APP_SHORT_NAME, | ||
46 | VITE_GLOB_API_URL_PREFIX, | 35 | VITE_GLOB_API_URL_PREFIX, |
47 | VITE_GLOB_UPLOAD_URL, | 36 | VITE_GLOB_UPLOAD_URL, |
48 | }; | 37 | }; |
types/config.d.ts
@@ -155,8 +155,6 @@ export interface GlobEnvConfig { | @@ -155,8 +155,6 @@ export interface GlobEnvConfig { | ||
155 | VITE_GLOB_API_URL: string; | 155 | VITE_GLOB_API_URL: string; |
156 | // Service interface url prefix | 156 | // Service interface url prefix |
157 | VITE_GLOB_API_URL_PREFIX?: string; | 157 | VITE_GLOB_API_URL_PREFIX?: string; |
158 | - // Project abbreviation | ||
159 | - VITE_GLOB_APP_SHORT_NAME: string; | ||
160 | // Upload url | 158 | // Upload url |
161 | VITE_GLOB_UPLOAD_URL?: string; | 159 | VITE_GLOB_UPLOAD_URL?: string; |
162 | } | 160 | } |
types/global.d.ts
@@ -61,7 +61,6 @@ declare global { | @@ -61,7 +61,6 @@ declare global { | ||
61 | VITE_PUBLIC_PATH: string; | 61 | VITE_PUBLIC_PATH: string; |
62 | VITE_PROXY: [string, string][]; | 62 | VITE_PROXY: [string, string][]; |
63 | VITE_GLOB_APP_TITLE: string; | 63 | VITE_GLOB_APP_TITLE: string; |
64 | - VITE_GLOB_APP_SHORT_NAME: string; | ||
65 | VITE_BUILD_COMPRESS: 'gzip' | 'brotli' | 'none'; | 64 | VITE_BUILD_COMPRESS: 'gzip' | 'brotli' | 'none'; |
66 | } | 65 | } |
67 | 66 |