Skip to content

Commit 7ddaf39

Browse files
committed
feat: Load on demand (loadfile)
Signed-off-by: Sendya <[email protected]>
1 parent 5b88067 commit 7ddaf39

File tree

6 files changed

+137
-0
lines changed

6 files changed

+137
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ yarn run lint
102102

103103
- 项目使用了在线 mock,[easy-mock](https://www.easy-mock.com/) 项目所用的 mock 数据 [点击查看(请勿改动接口返回数据)](https://www.easy-mock.com/project/5b7bce071f130e5b7fe8cd7d),也可以下载 [ANTD-PRO-Easy-Mock-API.zip](https://github.com/sendya/ant-design-pro-vue/files/2682711/ANTD-PRO-Easy-Mock-API.zip) 然后自行导入到自己的 mock 服务上
104104

105+
- 开启组件按需加载 `/src/main.js` L7 修改为 `import './core/lazy_use'`
106+
105107
- 修改 Ant Design 配色,在文件 `vue.config.js` 中,其他 less 变量覆盖参考 [ant design](https://ant.design/docs/react/customize-theme-cn) 官方说明
106108
```ecmascript 6
107109
css: {

babel.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,12 @@ module.exports = {
22
presets: [
33
'@vue/app'
44
]
5+
// ,
6+
// plugins: [
7+
// [ 'import', {
8+
// 'libraryName': 'ant-design-vue',
9+
// 'libraryDirectory': 'es',
10+
// 'style': true // `style: true` 会加载 less 文件
11+
// } ]
12+
// ]
513
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"babel-core": "7.0.0-bridge.0",
3838
"babel-eslint": "^10.0.1",
3939
"babel-jest": "^23.6.0",
40+
"babel-plugin-import": "^1.11.0",
4041
"eslint": "^5.8.0",
4142
"eslint-plugin-html": "^5.0.0",
4243
"eslint-plugin-vue": "^5.0.0",

src/core/lazy_lib/components_use.js

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
2+
/* eslint-disable */
3+
/**
4+
* 该文件是为了按需加载,剔除掉了一些不需要的框架组件。
5+
* 减少了编译支持库包大小
6+
*
7+
* 当需要更多组件依赖时,在该文件加入即可
8+
*/
9+
import Vue from 'vue'
10+
import {
11+
LocaleProvider,
12+
Layout,
13+
Input,
14+
InputNumber,
15+
Button,
16+
Switch,
17+
Radio,
18+
Checkbox,
19+
Select,
20+
Card,
21+
Form,
22+
Row,
23+
Col,
24+
Modal,
25+
Table,
26+
Tabs,
27+
Icon,
28+
Badge,
29+
Popover,
30+
Dropdown,
31+
List,
32+
Avatar,
33+
Breadcrumb,
34+
Steps,
35+
Spin,
36+
Menu,
37+
Drawer,
38+
Tooltip,
39+
Alert,
40+
Tag,
41+
Divider,
42+
DatePicker,
43+
TimePicker,
44+
Upload,
45+
Progress,
46+
Skeleton,
47+
Popconfirm,
48+
message,
49+
notification
50+
} from 'ant-design-vue'
51+
// import VueCropper from 'vue-cropper'
52+
53+
Vue.use(LocaleProvider)
54+
Vue.use(Layout)
55+
Vue.use(Input)
56+
Vue.use(InputNumber)
57+
Vue.use(Button)
58+
Vue.use(Switch)
59+
Vue.use(Radio)
60+
Vue.use(Checkbox)
61+
Vue.use(Select)
62+
Vue.use(Card)
63+
Vue.use(Form)
64+
Vue.use(Row)
65+
Vue.use(Col)
66+
Vue.use(Modal)
67+
Vue.use(Table)
68+
Vue.use(Tabs)
69+
Vue.use(Icon)
70+
Vue.use(Badge)
71+
Vue.use(Popover)
72+
Vue.use(Dropdown)
73+
Vue.use(List)
74+
Vue.use(Avatar)
75+
Vue.use(Breadcrumb)
76+
Vue.use(Steps)
77+
Vue.use(Spin)
78+
Vue.use(Menu)
79+
Vue.use(Drawer)
80+
Vue.use(Tooltip)
81+
Vue.use(Alert)
82+
Vue.use(Tag)
83+
Vue.use(Divider)
84+
Vue.use(DatePicker)
85+
Vue.use(TimePicker)
86+
Vue.use(Upload)
87+
Vue.use(Progress)
88+
Vue.use(Skeleton)
89+
Vue.use(Popconfirm)
90+
// Vue.use(VueCropper)
91+
Vue.use(notification)
92+
93+
Vue.prototype.$confirm = Modal.confirm
94+
Vue.prototype.$message = message
95+
Vue.prototype.$notification = notification
96+
Vue.prototype.$info = Modal.info
97+
Vue.prototype.$success = Modal.success
98+
Vue.prototype.$error = Modal.error
99+
Vue.prototype.$warning = Modal.warning

src/core/lazy_use.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import Vue from 'vue'
2+
import VueStorage from 'vue-ls'
3+
import config from '@/config/defaultSettings'
4+
5+
// base library
6+
import '@/core/lazy_lib/components_use'
7+
import Viser from 'viser-vue'
8+
9+
// ext library
10+
import VueClipboard from 'vue-clipboard2'
11+
import PermissionHelper from '@/utils/helper/permission'
12+
13+
VueClipboard.config.autoSetContainer = true
14+
15+
Vue.use(Viser)
16+
17+
Vue.use(VueStorage, config.storageOptions)
18+
Vue.use(VueClipboard)
19+
Vue.use(PermissionHelper)

yarn.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,6 +1821,14 @@ babel-plugin-dynamic-import-node@^2.2.0:
18211821
dependencies:
18221822
object.assign "^4.1.0"
18231823

1824+
babel-plugin-import@^1.11.0:
1825+
version "1.11.0"
1826+
resolved "https://registry.yarnpkg.com/babel-plugin-import/-/babel-plugin-import-1.11.0.tgz#78ac908e6b225206babb734e19eae5f78d6d1035"
1827+
integrity sha512-de9dWdU1YjmWRPYurlHRKD2hTd24z0bIQ0/JgyXqLMXML+TsvEkVhtqzOsNtu9MmCuvwBiTTTjZBbZXA1Xu7TQ==
1828+
dependencies:
1829+
"@babel/helper-module-imports" "^7.0.0"
1830+
"@babel/runtime" "^7.0.0"
1831+
18241832
babel-plugin-istanbul@^4.1.6:
18251833
version "4.1.6"
18261834
resolved "https://registry.yarnpkg.com/babel-plugin-istanbul/-/babel-plugin-istanbul-4.1.6.tgz#36c59b2192efce81c5b378321b74175add1c9a45"

0 commit comments

Comments
 (0)