-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
28 lines (25 loc) · 804 Bytes
/
index.js
File metadata and controls
28 lines (25 loc) · 804 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/**
* 自动局部组件预注册
* Lonay.(Liparty)
*/
import upperFirst from 'lodash/upperFirst'
import camelCase from 'lodash/camelCase'
export default _components = (path = '') => {
let _c = {}
//格式化路径。
if (path !== '') {
path.replace(/^\@/, '')
path = /\/$/.test(path) ? path.replace(/^\/(*.)/, '') : path + '/';
}
const requireComponent = require.context('./' + path, false, /\.vue$/);
requireComponent.keys().forEach(fileName => {
const componentConfig = requireComponent(fileName);
const componentName = upperFirst(
camelCase(
fileName.split('/').pop().replace(/\.\w+$/, '')
)
);
_c[componentName] = componentConfig.default || componentConfig;
})
return _c;
}