优化更新
This commit is contained in:
@@ -68,8 +68,8 @@ Vite 按 mode 加载环境变量,后面的文件覆盖前面的:
|
||||
|------|------|--------|------|
|
||||
| `VITE_PORT` | `number` | `8001` | 开发服务器端口 |
|
||||
| `VITE_PUBLIC_PATH` | `string` | `/` | 部署基础路径(子目录部署时修改) |
|
||||
| `VITE_GLOB_APP_TITLE` | `string` | `Django+ElementPlus版` | 应用标题(注入 HTML) |
|
||||
| `VITE_GLOB_APP_SHORT_NAME` | `string` | `Django+ElementPlus版` | 应用短名(用于生成运行时配置变量名) |
|
||||
| `VITE_GLOB_APP_TITLE` | `string` | `Django+AntDesign版` | 应用标题(注入 HTML) |
|
||||
| `VITE_GLOB_APP_SHORT_NAME` | `string` | `Django+AntDesign版` | 应用短名(用于生成运行时配置变量名) |
|
||||
| `VITE_GLOB_API_URL` | `string` | 空 | API 基础路径(留空使用相对路径) |
|
||||
| `VITE_GLOB_API_URL_PREFIX` | `string` | `/api` | API 前缀 |
|
||||
| `VITE_GLOB_FILE_URL` | `string` | - | 文件访问域名(拼接上传文件 URL) |
|
||||
@@ -177,7 +177,7 @@ import { defineStore } from 'pinia'; // 自动
|
||||
|
||||
```html
|
||||
<!-- 构建后的 index.html -->
|
||||
<title>Django+ElementPlus版</title>
|
||||
<title>Django+AntDesign版</title>
|
||||
<script src="/app.config.js?v=1.0.0-1725000000000"></script>
|
||||
```
|
||||
|
||||
@@ -192,7 +192,7 @@ window.__{SHORT_NAME}__PRODUCTION__CONF__ = {
|
||||
"VITE_GLOB_API_URL": "",
|
||||
"VITE_GLOB_API_URL_PREFIX": "/api",
|
||||
"VITE_GLOB_FILE_URL": "http://file.django.elevue",
|
||||
"VITE_GLOB_APP_TITLE": "Django+ElementPlus版",
|
||||
"VITE_GLOB_APP_TITLE": "Django+AntDesign版",
|
||||
// ...
|
||||
};
|
||||
Object.freeze(window.__{SHORT_NAME}__PRODUCTION__CONF__);
|
||||
@@ -256,7 +256,7 @@ dist/
|
||||
├── app.config.js # 运行时配置(VITE_GLOB_* 变量)
|
||||
├── favicon.ico # 网站图标
|
||||
└── assets/
|
||||
├── index-[hash].js # 主包(Vue、ElementPlus、Pinia 等)
|
||||
├── index-[hash].js # 主包(Vue、Ant Design Vue、Pinia 等)
|
||||
├── index-[hash].css # 全局样式
|
||||
├── [name]-[hash].js # 路由懒加载 chunk(按视图分割)
|
||||
└── ... # 字体、图片等静态资源
|
||||
@@ -283,7 +283,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` | 其他大型依赖 |
|
||||
|
||||
@@ -293,7 +293,7 @@ Vite 自动将 `node_modules` 中的库分割为独立 chunk:
|
||||
|
||||
```typescript
|
||||
optimizeDeps: {
|
||||
include: ['dayjs', '@vicons/ionicons5', '@vicons/antd', '@element-plus/icons-vue'],
|
||||
include: ['dayjs', '@ant-design/icons-vue'],
|
||||
}
|
||||
```
|
||||
|
||||
@@ -307,13 +307,8 @@ optimizeDeps: {
|
||||
async function bootstrap() {
|
||||
const app = createApp(App);
|
||||
|
||||
// 1. 全局注册 ElementPlus 图标
|
||||
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
|
||||
app.component(key, component);
|
||||
}
|
||||
|
||||
// 2. 全局引入 ElementPlus(中文包)
|
||||
setupElement(app);
|
||||
// 1. 全局注册 Ant Design Vue 组件
|
||||
setupAntd(app);
|
||||
|
||||
// 3. 全局注册自定义组件(BasicTable、BasicForm 等)
|
||||
setupCustomComponents(app);
|
||||
@@ -339,7 +334,7 @@ async function bootstrap() {
|
||||
|
||||
| 注册项 | 文件 | 说明 |
|
||||
|--------|------|------|
|
||||
| ElementPlus | `element.ts` | 全局引入 + 中文包 |
|
||||
| Ant Design Vue | `antdv.ts` | 全局引入组件 |
|
||||
| 自定义组件 | `customComponents.ts` | BasicTable、BasicForm、PageWrapper 等 |
|
||||
| 自定义指令 | `directives.ts` | `v-perm`、`v-perms`、`v-scrollBar` |
|
||||
|
||||
@@ -504,7 +499,7 @@ pnpm report
|
||||
**优化手段**:
|
||||
|
||||
1. 路由懒加载(已默认启用)
|
||||
2. 按需引入 ElementPlus 组件(当前为全量引入)
|
||||
2. 按需引入 Ant Design Vue 组件(当前为全量引入)
|
||||
3. 大型依赖(echarts、wangeditor)按需引入
|
||||
4. 开启 gzip 压缩(`VITE_BUILD_COMPRESS=gzip`)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user