Commit e8aedefb38e52a9363a2e63f9d241adc82fdde7e
1 parent
afbcf043
chore: separate configuration files
Showing
12 changed files
with
100 additions
and
38 deletions
.env
.env.development
1 | -VITE_USE_MOCK=true | |
1 | +# Whether to open mock | |
2 | +VITE_USE_MOCK = true | |
3 | + | |
4 | +# public path | |
5 | +VITE_PUBLIC_PATH = / | |
6 | + | |
7 | +# Basic interface address SPA | |
8 | +VITE_GLOB_API_URL=/api | |
9 | + | |
10 | +# Interface prefix | |
11 | +VITE_GLOB_API_URL_PREFIX= | |
12 | + | |
13 | +# Cross-domain proxy, you can configure multiple | |
14 | +VITE_PROXY=[["/api","http://localhost:3000"]] | ... | ... |
.env.production
.vscode/extensions.json
1 | 1 | { |
2 | 2 | "recommendations": [ |
3 | 3 | "octref.vetur", |
4 | - "dariofuzinato.vue-peek", | |
5 | 4 | "dbaeumer.vscode-eslint", |
6 | 5 | "stylelint.vscode-stylelint", |
7 | 6 | "DavidAnson.vscode-markdownlint", |
8 | 7 | "esbenp.prettier-vscode", |
9 | 8 | "mrmlnc.vscode-scss", |
10 | - "Orta.vscode-jest" | |
9 | + "mrmlnc.vscode-less", | |
10 | + "cpylua.language-postcss", | |
11 | + "Orta.vscode-jest", | |
12 | + "antfu.iconify", | |
13 | + "mikestead.dotenv", | |
14 | + "bradlc.vscode-tailwindcss" | |
11 | 15 | ] |
12 | 16 | } | ... | ... |
README.md
... | ... | @@ -111,7 +111,7 @@ git clone https://github.com/anncwb/vue-vben-admin.git vue-vben-admin-2.0 |
111 | 111 | |
112 | 112 | cd vue-vben-admin-2.0 |
113 | 113 | |
114 | -// 如果使用别的包,可以执行安装 | |
114 | +// 如果使用别的包管理工具,可以自行安装 | |
115 | 115 | // 如果未安装yarn,请运行:npm install -g yarn |
116 | 116 | yarn install |
117 | 117 | |
... | ... | @@ -174,7 +174,7 @@ yarn clean:lib # 删除node_modules,兼容window系统 |
174 | 174 | - `workflow` 工作流改进 |
175 | 175 | - `ci` 持续集成 |
176 | 176 | - `types` 类型定义文件更改 |
177 | - - `wip` 删除文件 | |
177 | + - `wip` 开发中 | |
178 | 178 | |
179 | 179 | ## 代码贡献 |
180 | 180 | |
... | ... | @@ -212,10 +212,8 @@ yarn clean:lib # 删除node_modules,兼容window系统 |
212 | 212 | - [x] 二维码插件 |
213 | 213 | - [x] 国际化插件 |
214 | 214 | - [x] 详情组件 |
215 | -- [x] 图片裁剪 | |
216 | 215 | - [x] 验证码/验证组件 |
217 | 216 | - [x] 树组件 |
218 | -- [x] 系统性能优化 | |
219 | 217 | - [x] 兼容最新`vuex`,`vue-router` |
220 | 218 | - [x] 图片预览组件 |
221 | 219 | - [x] 表格组件 |
... | ... | @@ -234,6 +232,7 @@ yarn clean:lib # 删除node_modules,兼容window系统 |
234 | 232 | - [ ] 黑暗主题 |
235 | 233 | - [ ] 打包 Gzip |
236 | 234 | - [ ] 抽取生产环境配置文件 |
235 | +- [ ] 系统性能优化 | |
237 | 236 | |
238 | 237 | 更多组件/功能/建议/bug/欢迎提交 pr 或者 issue |
239 | 238 | ... | ... |
build/utils.ts
1 | 1 | import fs from 'fs'; |
2 | 2 | import { networkInterfaces } from 'os'; |
3 | 3 | import dotenv from 'dotenv'; |
4 | - | |
5 | 4 | export const isFunction = (arg: unknown): arg is (...args: any[]) => any => |
6 | 5 | typeof arg === 'function'; |
7 | 6 | export const isRegExp = (arg: unknown): arg is RegExp => |
... | ... | @@ -68,7 +67,14 @@ export function isReportMode(): boolean { |
68 | 67 | return process.env.REPORT === 'true'; |
69 | 68 | } |
70 | 69 | |
71 | -export function loadEnv() { | |
70 | +export interface ViteEnv { | |
71 | + VITE_PORT: number; | |
72 | + VITE_USE_MOCK: boolean; | |
73 | + VITE_PUBLIC_PATH: string; | |
74 | + VITE_PROXY: [string, string][]; | |
75 | +} | |
76 | + | |
77 | +export function loadEnv(): ViteEnv { | |
72 | 78 | const env = process.env.NODE_ENV; |
73 | 79 | const ret: any = {}; |
74 | 80 | const envList = [`.env.${env}.local`, `.env.${env}`, '.env.local', '.env', ,]; |
... | ... | @@ -79,7 +85,16 @@ export function loadEnv() { |
79 | 85 | }); |
80 | 86 | |
81 | 87 | for (const envName of Object.keys(process.env)) { |
82 | - const realName = (process.env as any)[envName].replace(/\\n/g, '\n'); | |
88 | + let realName = (process.env as any)[envName].replace(/\\n/g, '\n'); | |
89 | + realName = realName === 'true' ? true : realName === 'false' ? false : realName; | |
90 | + if (envName === 'VITE_PORT') { | |
91 | + realName = Number(realName); | |
92 | + } | |
93 | + if (envName === 'VITE_PROXY') { | |
94 | + try { | |
95 | + realName = JSON.parse(realName); | |
96 | + } catch (error) {} | |
97 | + } | |
83 | 98 | ret[envName] = realName; |
84 | 99 | process.env[envName] = realName; |
85 | 100 | } | ... | ... |
getEnvConfig.ts
0 → 100644
package.json
... | ... | @@ -82,7 +82,7 @@ |
82 | 82 | "stylelint-config-prettier": "^8.0.2", |
83 | 83 | "stylelint-config-standard": "^20.0.0", |
84 | 84 | "stylelint-order": "^4.1.0", |
85 | - "tailwindcss": "^1.8.10", | |
85 | + "tailwindcss": "^1.8.13", | |
86 | 86 | "tasksfile": "^5.1.1", |
87 | 87 | "ts-node": "^9.0.0", |
88 | 88 | "typescript": "^4.0.3", | ... | ... |
src/hooks/core/useSetting.ts
... | ... | @@ -2,13 +2,21 @@ import type { ProjectConfig, GlobConfig, SettingWrap } from '/@/types/config'; |
2 | 2 | |
3 | 3 | import getProjectSetting from '/@/settings/projectSetting'; |
4 | 4 | |
5 | +import { getGlobEnvConfig } from '../../../getEnvConfig'; | |
6 | +const { | |
7 | + VITE_GLOB_API_URL, | |
8 | + VITE_GLOB_APP_SHORT_NAME, | |
9 | + VITE_GLOB_APP_TITLE, | |
10 | + VITE_GLOB_API_URL_PREFIX, | |
11 | +} = getGlobEnvConfig(); | |
12 | + | |
5 | 13 | export const useSetting = (): SettingWrap => { |
6 | 14 | // Take global configuration |
7 | 15 | const glob: Readonly<GlobConfig> = { |
8 | - title: 'vben admin 2.0', | |
9 | - apiUrl: '/api', | |
10 | - shortName: 'vben_admin_v2', | |
11 | - urlPrefix: '', | |
16 | + title: VITE_GLOB_APP_TITLE, | |
17 | + apiUrl: VITE_GLOB_API_URL, | |
18 | + shortName: VITE_GLOB_APP_SHORT_NAME, | |
19 | + urlPrefix: VITE_GLOB_API_URL_PREFIX, | |
12 | 20 | }; |
13 | 21 | const projectSetting: Readonly<ProjectConfig> = getProjectSetting; |
14 | 22 | ... | ... |
src/types/config.d.ts
... | ... | @@ -117,14 +117,14 @@ export interface GlobConfig { |
117 | 117 | } |
118 | 118 | export interface GlobEnvConfig { |
119 | 119 | // 网站标题 |
120 | - GLOB_APP_TITLE: string; | |
120 | + VITE_GLOB_APP_TITLE: string; | |
121 | 121 | |
122 | 122 | // 项目路径 |
123 | - GLOB_API_URL: string; | |
123 | + VITE_GLOB_API_URL: string; | |
124 | 124 | |
125 | - GLOB_API_URL_PREFIX?: string; | |
125 | + VITE_GLOB_API_URL_PREFIX?: string; | |
126 | 126 | |
127 | - GLOB_APP_SHORT_NAME: string; | |
127 | + VITE_GLOB_APP_SHORT_NAME: string; | |
128 | 128 | } |
129 | 129 | |
130 | 130 | // 修改配置 | ... | ... |
vite.config.ts
1 | 1 | import { resolve } from 'path'; |
2 | 2 | |
3 | 3 | import type { UserConfig, Plugin as VitePlugin } from 'vite'; |
4 | -import type { Plugin } from 'rollup'; | |
5 | 4 | |
6 | 5 | import visualizer from 'rollup-plugin-visualizer'; |
7 | 6 | import { modifyVars } from './build/config/glob/lessModifyVars'; |
... | ... | @@ -12,12 +11,13 @@ import PurgeIcons from 'vite-plugin-purge-icons'; |
12 | 11 | import { isDevFn, isReportMode, isProdFn, loadEnv } from './build/utils'; |
13 | 12 | |
14 | 13 | setupBasicEnv(); |
15 | -const { VITE_USE_MOCK } = loadEnv(); | |
14 | +const { VITE_USE_MOCK, VITE_PORT, VITE_PUBLIC_PATH, VITE_PROXY } = loadEnv(); | |
16 | 15 | |
17 | 16 | function pathResolve(dir: string) { |
18 | 17 | return resolve(__dirname, '.', dir); |
19 | 18 | } |
20 | -const rollupPlugins: Plugin[] = []; | |
19 | + | |
20 | +const rollupPlugins: any[] = []; | |
21 | 21 | const vitePlugins: VitePlugin[] = []; |
22 | 22 | |
23 | 23 | (() => { |
... | ... | @@ -27,7 +27,7 @@ const vitePlugins: VitePlugin[] = []; |
27 | 27 | visualizer({ filename: './node_modules/.cache/stats.html', open: true }) as Plugin |
28 | 28 | ); |
29 | 29 | } |
30 | - if (isDevFn() && VITE_USE_MOCK === 'true') { | |
30 | + if (isDevFn() && VITE_USE_MOCK) { | |
31 | 31 | // open mock |
32 | 32 | vitePlugins.push( |
33 | 33 | createMockServer({ |
... | ... | @@ -39,18 +39,17 @@ const vitePlugins: VitePlugin[] = []; |
39 | 39 | })(); |
40 | 40 | |
41 | 41 | const viteConfig: UserConfig = { |
42 | - silent: false, | |
42 | + /** | |
43 | + * 端口号 | |
44 | + * @default '3000' | |
45 | + */ | |
46 | + port: VITE_PORT, | |
43 | 47 | /** |
44 | 48 | * 服务地址 |
45 | 49 | * @default 'localhost' |
46 | 50 | */ |
47 | 51 | hostname: 'localhost', |
48 | 52 | /** |
49 | - * 端口号 | |
50 | - * @default '3000' | |
51 | - */ | |
52 | - port: 3100, | |
53 | - /** | |
54 | 53 | * 运行自动打开浏览器· |
55 | 54 | * @default 'false' |
56 | 55 | */ |
... | ... | @@ -62,10 +61,10 @@ const viteConfig: UserConfig = { |
62 | 61 | */ |
63 | 62 | minify: isDevFn() ? false : 'terser', |
64 | 63 | /** |
65 | - * 在生产中投放时提供基本公共路径 | |
64 | + * 基本公共路径 | |
66 | 65 | * @default '/' |
67 | 66 | */ |
68 | - base: isDevFn() ? '/' : './', | |
67 | + base: VITE_PUBLIC_PATH, | |
69 | 68 | |
70 | 69 | /** |
71 | 70 | * 打包输入路径 |
... | ... | @@ -91,7 +90,7 @@ const viteConfig: UserConfig = { |
91 | 90 | * @default 'es2019' |
92 | 91 | */ |
93 | 92 | esbuildTarget: 'es2019', |
94 | - | |
93 | + silent: false, | |
95 | 94 | // 别名 |
96 | 95 | alias: { |
97 | 96 | '/@/': pathResolve('src'), |
... | ... | @@ -112,7 +111,7 @@ const viteConfig: UserConfig = { |
112 | 111 | include: ['ant-design-vue/es/locale/zh_CN', '@ant-design/icons-vue', 'moment/locale/zh-cn'], |
113 | 112 | }, |
114 | 113 | // 本地跨域代理 |
115 | - proxy: createProxy([['/api', 'http://localhost:3000']]), | |
114 | + proxy: createProxy(VITE_PROXY), | |
116 | 115 | |
117 | 116 | plugins: [PurgeIcons(), ...vitePlugins], |
118 | 117 | rollupOutputOptions: {}, | ... | ... |
yarn.lock
... | ... | @@ -6478,10 +6478,10 @@ table@^6.0.1: |
6478 | 6478 | slice-ansi "^4.0.0" |
6479 | 6479 | string-width "^4.2.0" |
6480 | 6480 | |
6481 | -tailwindcss@^1.8.10: | |
6482 | - version "1.8.10" | |
6483 | - resolved "https://registry.npm.taobao.org/tailwindcss/download/tailwindcss-1.8.10.tgz#945ef151c401c04a1c95e6a6bc747387a8d1b9dc" | |
6484 | - integrity sha1-lF7xUcQBwEocleamvHRzh6jRudw= | |
6481 | +tailwindcss@^1.8.13: | |
6482 | + version "1.8.13" | |
6483 | + resolved "https://registry.npmjs.org/tailwindcss/-/tailwindcss-1.8.13.tgz#ee57050a516d342bafc92cb74b4de6f92e44c189" | |
6484 | + integrity sha512-z3R/6qPqfjauSR4qHhlA8I0OnfSyuotvigXISq666k+V52VSs5HV//KZ0Xe3qrZ4h5Um4OG5g+lcgjXSfURjDw== | |
6485 | 6485 | dependencies: |
6486 | 6486 | "@fullhuman/postcss-purgecss" "^2.1.2" |
6487 | 6487 | autoprefixer "^9.4.5" | ... | ... |