Commit 968f791f4b7112730813c8c990379051c3f8340d
1 parent
c2333f5d
perf: optimize the size of the first screen
Showing
11 changed files
with
43 additions
and
26 deletions
CHANGELOG.zh_CN.md
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 | import { Ref, ref, watch, unref } from 'vue'; | 1 | import { Ref, ref, watch, unref } from 'vue'; |
11 | import { BasicTableProps } from '../types/table'; | 2 | import { BasicTableProps } from '../types/table'; |
12 | 3 |
src/components/Table/src/props.ts
@@ -133,7 +133,7 @@ export const basicProps = { | @@ -133,7 +133,7 @@ export const basicProps = { | ||
133 | }, | 133 | }, |
134 | bordered: { | 134 | bordered: { |
135 | type: Boolean as PropType<boolean>, | 135 | type: Boolean as PropType<boolean>, |
136 | - default: true, | 136 | + default: false, |
137 | }, | 137 | }, |
138 | pagination: { | 138 | pagination: { |
139 | type: [Object, Boolean] as PropType<PaginationProps | boolean>, | 139 | type: [Object, Boolean] as PropType<PaginationProps | boolean>, |
src/components/registerGlobComp.ts
1 | import Icon from './Icon/index'; | 1 | import Icon from './Icon/index'; |
2 | import { BasicHelp, BasicTitle } from './Basic'; | 2 | import { BasicHelp, BasicTitle } from './Basic'; |
3 | import Button from './Button/index.vue'; | 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 | compList.forEach((comp: any) => { | 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 '/@/enums/menuEnum'; | @@ -13,12 +13,17 @@ import { MenuModeEnum, MenuTypeEnum } from '/@/enums/menuEnum'; | ||
13 | import { useFullContent } from '/@/hooks/web/useFullContent'; | 13 | import { useFullContent } from '/@/hooks/web/useFullContent'; |
14 | 14 | ||
15 | import LockPage from '/@/views/sys/lock/index.vue'; | 15 | import LockPage from '/@/views/sys/lock/index.vue'; |
16 | +import { registerGlobComp } from '/@/components/registerGlobComp'; | ||
16 | 17 | ||
17 | import './index.less'; | 18 | import './index.less'; |
18 | -// import { userStore } from '/@/store/modules/user'; | ||
19 | export default defineComponent({ | 19 | export default defineComponent({ |
20 | name: 'DefaultLayout', | 20 | name: 'DefaultLayout', |
21 | setup() { | 21 | setup() { |
22 | + // ! 在这里才注册全局组件 | ||
23 | + // ! 可以减少首屏代码体积 | ||
24 | + // default layout是在登录后才加载的。所以不会打包到首屏去 | ||
25 | + registerGlobComp(); | ||
26 | + | ||
22 | // 获取项目配置 | 27 | // 获取项目配置 |
23 | const { getFullContent } = useFullContent(); | 28 | const { getFullContent } = useFullContent(); |
24 | 29 |
src/layouts/default/setting/index.vue
1 | <template> | 1 | <template> |
2 | <div @click="openDrawer" class="setting-button"> | 2 | <div @click="openDrawer" class="setting-button"> |
3 | - <SettingOutlined :spin="true" /> | 3 | + <SettingOutlined /> |
4 | <SettingDrawer @register="register" /> | 4 | <SettingDrawer @register="register" /> |
5 | </div> | 5 | </div> |
6 | </template> | 6 | </template> |
src/main.ts
@@ -6,9 +6,9 @@ import { setupAntd } from '/@/setup/ant-design-vue'; | @@ -6,9 +6,9 @@ import { setupAntd } from '/@/setup/ant-design-vue'; | ||
6 | import { setupErrorHandle } from '/@/setup/error-handle/index'; | 6 | import { setupErrorHandle } from '/@/setup/error-handle/index'; |
7 | import { setupDirectives } from '/@/setup/directives/index'; | 7 | import { setupDirectives } from '/@/setup/directives/index'; |
8 | 8 | ||
9 | -import { registerGlobComp } from '/@/components/registerGlobComp'; | ||
10 | import { isDevMode, isProdMode, isUseMock } from '/@/utils/env'; | 9 | import { isDevMode, isProdMode, isUseMock } from '/@/utils/env'; |
11 | import { setupProdMockServer } from '../mock/_createProductionServer'; | 10 | import { setupProdMockServer } from '../mock/_createProductionServer'; |
11 | +import { setApp } from './useApp'; | ||
12 | 12 | ||
13 | import App from './App.vue'; | 13 | import App from './App.vue'; |
14 | import '/@/design/index.less'; | 14 | import '/@/design/index.less'; |
@@ -26,8 +26,6 @@ setupDirectives(app); | @@ -26,8 +26,6 @@ setupDirectives(app); | ||
26 | 26 | ||
27 | setupErrorHandle(app); | 27 | setupErrorHandle(app); |
28 | 28 | ||
29 | -registerGlobComp(app); | ||
30 | - | ||
31 | router.isReady().then(() => { | 29 | router.isReady().then(() => { |
32 | app.mount('#app'); | 30 | app.mount('#app'); |
33 | }); | 31 | }); |
@@ -40,4 +38,5 @@ if (isDevMode()) { | @@ -40,4 +38,5 @@ if (isDevMode()) { | ||
40 | if (isProdMode() && isUseMock()) { | 38 | if (isProdMode() && isUseMock()) { |
41 | setupProdMockServer(); | 39 | setupProdMockServer(); |
42 | } | 40 | } |
43 | -export default app; | 41 | + |
42 | +setApp(app); |
src/setup/ant-design-vue/index.ts
@@ -2,13 +2,13 @@ | @@ -2,13 +2,13 @@ | ||
2 | 2 | ||
3 | import type { App } from 'vue'; | 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 | import 'ant-design-vue/dist/antd.css'; | 6 | import 'ant-design-vue/dist/antd.css'; |
7 | 7 | ||
8 | import './spin'; | 8 | import './spin'; |
9 | 9 | ||
10 | export function setupAntd(app: App<Element>) { | 10 | export function setupAntd(app: App<Element>) { |
11 | - app.component(Button.Group.name, Button.Group); | 11 | + // 这两个组件在登录也就用。全局注册 |
12 | app.use(Form); | 12 | app.use(Form); |
13 | app.use(Input); | 13 | app.use(Input); |
14 | } | 14 | } |
src/useApp.ts
1 | import type { ProjectConfig } from '/@/types/config'; | 1 | import type { ProjectConfig } from '/@/types/config'; |
2 | - | 2 | +import type { App } from 'vue'; |
3 | import { computed, ref } from 'vue'; | 3 | import { computed, ref } from 'vue'; |
4 | 4 | ||
5 | import { ThemeModeEnum } from '/@/enums/appEnum'; | 5 | import { ThemeModeEnum } from '/@/enums/appEnum'; |
@@ -17,6 +17,15 @@ import { PageEnum } from '/@/enums/pageEnum'; | @@ -17,6 +17,15 @@ import { PageEnum } from '/@/enums/pageEnum'; | ||
17 | import { useTimeout } from '/@/hooks/core/useTimeout'; | 17 | import { useTimeout } from '/@/hooks/core/useTimeout'; |
18 | import { ExceptionEnum } from '/@/enums/exceptionEnum'; | 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 | // TODO 主题切换 | 29 | // TODO 主题切换 |
21 | export function useThemeMode(mode: ThemeModeEnum) { | 30 | export function useThemeMode(mode: ThemeModeEnum) { |
22 | const modeRef = ref(mode); | 31 | const modeRef = ref(mode); |
src/views/sys/login/Login.vue
@@ -49,8 +49,10 @@ | @@ -49,8 +49,10 @@ | ||
49 | import { appStore } from '/@/store/modules/app'; | 49 | import { appStore } from '/@/store/modules/app'; |
50 | import { useMessage } from '/@/hooks/web/useMessage'; | 50 | import { useMessage } from '/@/hooks/web/useMessage'; |
51 | import { useSetting } from '/@/hooks/core/useSetting'; | 51 | import { useSetting } from '/@/hooks/core/useSetting'; |
52 | + import Button from '/@/components/Button/index.vue'; | ||
53 | + | ||
52 | export default defineComponent({ | 54 | export default defineComponent({ |
53 | - components: { BasicDragVerify }, | 55 | + components: { BasicDragVerify, AButton: Button }, |
54 | setup() { | 56 | setup() { |
55 | const { globSetting } = useSetting(); | 57 | const { globSetting } = useSetting(); |
56 | const { notification } = useMessage(); | 58 | const { notification } = useMessage(); |
vite.config.ts
@@ -133,8 +133,7 @@ const viteConfig: UserConfig = { | @@ -133,8 +133,7 @@ const viteConfig: UserConfig = { | ||
133 | javascriptEnabled: true, | 133 | javascriptEnabled: true, |
134 | }, | 134 | }, |
135 | }, | 135 | }, |
136 | - // 配置Dep优化行为 | ||
137 | - // 会使用 rollup 对 包重新编译,将编译成符合 esm 模块规范的新的包放入 node_modules 下的 . | 136 | + // 会使用 rollup 对 包重新编译,将编译成符合 esm 模块规范的新的包放入 node_modules/.vite_opt_cache |
138 | optimizeDeps: { | 137 | optimizeDeps: { |
139 | include: [ | 138 | include: [ |
140 | 'echarts', | 139 | 'echarts', |