Commit 968f791f4b7112730813c8c990379051c3f8340d

Authored by vben
1 parent c2333f5d

perf: optimize the size of the first screen

CHANGELOG.zh_CN.md
  1 +# Wip
  2 +
  3 +### ⚡ Performance Improvements
  4 +
  5 +- 优化首屏体积大小
  6 +
  7 +### 🐛 Bug Fixes
  8 +
  9 +- 修复一级菜单折叠显示菜单名问题
  10 +- 修复预览命令不打包问题
  11 +
1 12 # 2.0.0-rc.3 (2020-10-19)
2 13  
3 14 ### ✨ Features
... ...
src/components/Table/src/hooks/useProps.ts
1   -/*
2   - * @description:
3   - * @author: wenbin.chen
4   - * @Date: 2020-05-12 13:20:26
5   - * @LastEditors: vben
6   - * @LastEditTime: 2020-10-07 14:52:34
7   - * @email: 190848757@qq.com
8   - */
9   -
10 1 import { Ref, ref, watch, unref } from 'vue';
11 2 import { BasicTableProps } from '../types/table';
12 3  
... ...
src/components/Table/src/props.ts
... ... @@ -133,7 +133,7 @@ export const basicProps = {
133 133 },
134 134 bordered: {
135 135 type: Boolean as PropType<boolean>,
136   - default: true,
  136 + default: false,
137 137 },
138 138 pagination: {
139 139 type: [Object, Boolean] as PropType<PaginationProps | boolean>,
... ...
src/components/registerGlobComp.ts
1 1 import Icon from './Icon/index';
2 2 import { BasicHelp, BasicTitle } from './Basic';
3 3 import Button from './Button/index.vue';
4   -import { App } from 'vue';
  4 +import { Button as AntButton } from 'ant-design-vue';
  5 +import { getApp } from '/@/useApp';
5 6  
6   -const compList = [Icon, BasicHelp, BasicTitle, Button];
7   -export function registerGlobComp(app: App<Element>) {
  7 +const compList = [Icon, BasicHelp, BasicTitle, Button, AntButton.Group];
  8 +export function registerGlobComp() {
8 9 compList.forEach((comp: any) => {
9   - app.component(comp.name, comp);
  10 + getApp().component(comp.name, comp);
10 11 });
11 12 }
... ...
src/layouts/default/index.tsx
... ... @@ -13,12 +13,17 @@ import { MenuModeEnum, MenuTypeEnum } from &#39;/@/enums/menuEnum&#39;;
13 13 import { useFullContent } from '/@/hooks/web/useFullContent';
14 14  
15 15 import LockPage from '/@/views/sys/lock/index.vue';
  16 +import { registerGlobComp } from '/@/components/registerGlobComp';
16 17  
17 18 import './index.less';
18   -// import { userStore } from '/@/store/modules/user';
19 19 export default defineComponent({
20 20 name: 'DefaultLayout',
21 21 setup() {
  22 + // ! 在这里才注册全局组件
  23 + // ! 可以减少首屏代码体积
  24 + // default layout是在登录后才加载的。所以不会打包到首屏去
  25 + registerGlobComp();
  26 +
22 27 // 获取项目配置
23 28 const { getFullContent } = useFullContent();
24 29  
... ...
src/layouts/default/setting/index.vue
1 1 <template>
2 2 <div @click="openDrawer" class="setting-button">
3   - <SettingOutlined :spin="true" />
  3 + <SettingOutlined />
4 4 <SettingDrawer @register="register" />
5 5 </div>
6 6 </template>
... ...
src/main.ts
... ... @@ -6,9 +6,9 @@ import { setupAntd } from &#39;/@/setup/ant-design-vue&#39;;
6 6 import { setupErrorHandle } from '/@/setup/error-handle/index';
7 7 import { setupDirectives } from '/@/setup/directives/index';
8 8  
9   -import { registerGlobComp } from '/@/components/registerGlobComp';
10 9 import { isDevMode, isProdMode, isUseMock } from '/@/utils/env';
11 10 import { setupProdMockServer } from '../mock/_createProductionServer';
  11 +import { setApp } from './useApp';
12 12  
13 13 import App from './App.vue';
14 14 import '/@/design/index.less';
... ... @@ -26,8 +26,6 @@ setupDirectives(app);
26 26  
27 27 setupErrorHandle(app);
28 28  
29   -registerGlobComp(app);
30   -
31 29 router.isReady().then(() => {
32 30 app.mount('#app');
33 31 });
... ... @@ -40,4 +38,5 @@ if (isDevMode()) {
40 38 if (isProdMode() && isUseMock()) {
41 39 setupProdMockServer();
42 40 }
43   -export default app;
  41 +
  42 +setApp(app);
... ...
src/setup/ant-design-vue/index.ts
... ... @@ -2,13 +2,13 @@
2 2  
3 3 import type { App } from 'vue';
4 4  
5   -import { Form, Input, Button } from 'ant-design-vue';
  5 +import { Form, Input } from 'ant-design-vue';
6 6 import 'ant-design-vue/dist/antd.css';
7 7  
8 8 import './spin';
9 9  
10 10 export function setupAntd(app: App<Element>) {
11   - app.component(Button.Group.name, Button.Group);
  11 + // 这两个组件在登录也就用。全局注册
12 12 app.use(Form);
13 13 app.use(Input);
14 14 }
... ...
src/useApp.ts
1 1 import type { ProjectConfig } from '/@/types/config';
2   -
  2 +import type { App } from 'vue';
3 3 import { computed, ref } from 'vue';
4 4  
5 5 import { ThemeModeEnum } from '/@/enums/appEnum';
... ... @@ -17,6 +17,15 @@ import { PageEnum } from &#39;/@/enums/pageEnum&#39;;
17 17 import { useTimeout } from '/@/hooks/core/useTimeout';
18 18 import { ExceptionEnum } from '/@/enums/exceptionEnum';
19 19  
  20 +let app: App;
  21 +export function setApp(_app: App): void {
  22 + app = _app;
  23 +}
  24 +
  25 +export function getApp(): App {
  26 + return app;
  27 +}
  28 +
20 29 // TODO 主题切换
21 30 export function useThemeMode(mode: ThemeModeEnum) {
22 31 const modeRef = ref(mode);
... ...
src/views/sys/login/Login.vue
... ... @@ -49,8 +49,10 @@
49 49 import { appStore } from '/@/store/modules/app';
50 50 import { useMessage } from '/@/hooks/web/useMessage';
51 51 import { useSetting } from '/@/hooks/core/useSetting';
  52 + import Button from '/@/components/Button/index.vue';
  53 +
52 54 export default defineComponent({
53   - components: { BasicDragVerify },
  55 + components: { BasicDragVerify, AButton: Button },
54 56 setup() {
55 57 const { globSetting } = useSetting();
56 58 const { notification } = useMessage();
... ...
vite.config.ts
... ... @@ -133,8 +133,7 @@ const viteConfig: UserConfig = {
133 133 javascriptEnabled: true,
134 134 },
135 135 },
136   - // 配置Dep优化行为
137   - // 会使用 rollup 对 包重新编译,将编译成符合 esm 模块规范的新的包放入 node_modules 下的 .
  136 + // 会使用 rollup 对 包重新编译,将编译成符合 esm 模块规范的新的包放入 node_modules/.vite_opt_cache
138 137 optimizeDeps: {
139 138 include: [
140 139 'echarts',
... ...