优化更新

This commit is contained in:
2026-09-14 09:44:33 +08:00
parent b3a9e21254
commit 5b8e178970
60 changed files with 1243 additions and 1022 deletions
@@ -66,8 +66,8 @@ Vite 按 mode 加载环境变量,后面的文件覆盖前面的:
|------|------|--------|------|
| `VITE_PORT` | `number` | `8001` | 开发服务器端口 |
| `VITE_PUBLIC_PATH` | `string` | `/` | 部署基础路径(子目录部署时修改) |
| `VITE_GLOB_APP_TITLE` | `string` | `FastAPI+ElementPlus版` | 应用标题(注入 HTML) |
| `VITE_GLOB_APP_SHORT_NAME` | `string` | `FastAPI+ElementPlus版` | 应用短名(用于生成运行时配置变量名) |
| `VITE_GLOB_APP_TITLE` | `string` | `FastAPI+AntDesign版` | 应用标题(注入 HTML) |
| `VITE_GLOB_APP_SHORT_NAME` | `string` | `FastAPI+AntDesign版` | 应用短名(用于生成运行时配置变量名) |
| `VITE_GLOB_API_URL` | `string` | 空 | API 基础路径(留空使用相对路径) |
| `VITE_GLOB_API_URL_PREFIX` | `string` | `/api` | API 前缀 |
| `VITE_GLOB_FILE_URL` | `string` | - | 文件访问域名(拼接上传文件 URL) |
@@ -175,7 +175,7 @@ import { defineStore } from 'pinia'; // 自动
```html
<!-- 构建后的 index.html -->
<title>FastAPI+ElementPlus版</title>
<title>FastAPI+AntDesign版</title>
<script src="/app.config.js?v=1.0.0-1725000000000"></script>
```
@@ -185,14 +185,14 @@ import { defineStore } from 'pinia'; // 自动
```javascript
// dist/app.config.js(构建后自动生成,不可手动修改)
window.__PRODUCTION_FASTAPI_ELEMENTPLUS___CONF__ = {
window.__PRODUCTION_FASTAPI_ANTDESIGN___CONF__ = {
"VITE_GLOB_API_URL": "",
"VITE_GLOB_API_URL_PREFIX": "/api",
"VITE_GLOB_FILE_URL": "http://file.fastapi.elevue",
"VITE_GLOB_APP_TITLE": "FastAPI+ElementPlus版",
"VITE_GLOB_FILE_URL": "http://file.fastapi.antdvue",
"VITE_GLOB_APP_TITLE": "FastAPI+AntDesign版",
// ...
};
Object.freeze(window.__PRODUCTION_FASTAPI_ELEMENTPLUS___CONF__);
Object.freeze(window.__PRODUCTION_FASTAPI_ANTDESIGN___CONF__);
```
:::warning 为什么需要运行时配置?
@@ -249,7 +249,7 @@ dist/
├── app.config.js # 运行时配置(VITE_GLOB_* 变量)
├── favicon.ico # 网站图标
└── assets/
├── index-[hash].js # 主包(Vue、ElementPlus、Pinia 等)
├── index-[hash].js # 主包(Vue、AntDesign Vue、Pinia 等)
├── index-[hash].css # 全局样式
├── [name]-[hash].js # 路由懒加载 chunk(按视图分割)
└── ... # 字体、图片等静态资源
@@ -276,7 +276,7 @@ Vite 自动将 `node_modules` 中的库分割为独立 chunk:
| chunk | 内容 |
|-------|------|
| `vendor-vue.js` | vue + vue-router + pinia |
| `vendor-element.js` | element-plus |
| `vendor-antd.js` | ant-design-vue |
| `vendor-echarts.js` | echarts(如果使用) |
| `vendor-*.js` | 其他大型依赖 |
@@ -286,7 +286,7 @@ Vite 自动将 `node_modules` 中的库分割为独立 chunk:
```typescript
optimizeDeps: {
include: ['dayjs', '@vicons/ionicons5', '@vicons/antd', '@element-plus/icons-vue'],
include: ['dayjs', '@vicons/ionicons5', '@vicons/antd', '@ant-design/icons-vue'],
}
```
@@ -300,13 +300,13 @@ optimizeDeps: {
async function bootstrap() {
const app = createApp(App);
// 1. 全局注册 ElementPlus 图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
// 1. 全局注册 AntDesign Vue 图标
for (const [key, component] of Object.entries(AntdIconsVue)) {
app.component(key, component);
}
// 2. 全局引入 ElementPlus(中文包)
setupElement(app);
// 2. 全局引入 AntDesign Vue(中文包)
setupAntd(app);
// 3. 全局注册自定义组件(BasicTable、BasicForm 等)
setupCustomComponents(app);
@@ -332,7 +332,7 @@ async function bootstrap() {
| 注册项 | 文件 | 说明 |
|--------|------|------|
| ElementPlus | `element.ts` | 全局引入 + 中文包 |
| AntDesign Vue | `antd.ts` | 全局引入 + 中文包 |
| 自定义组件 | `customComponents.ts` | BasicTable、BasicForm、PageWrapper 等 |
| 自定义指令 | `directives.ts` | `v-perm`、`v-perms`、`v-scrollBar` |
@@ -497,7 +497,7 @@ pnpm report
**优化手段**:
1. 路由懒加载(已默认启用)
2. 按需引入 ElementPlus 组件(当前为全量引入)
2. 按需引入 AntDesign Vue 组件(当前为全量引入)
3. 大型依赖(echarts、wangeditor)按需引入
4. 开启 gzip 压缩(`VITE_BUILD_COMPRESS=gzip`)