1
+ import { basename , extname } from 'path'
1
2
export { default as config } from './config'
2
3
export { default as ContentPlaceholder } from './components/ContentPlaceholder.vue'
3
4
export { default as DonateForm } from './components/DonateForm.vue'
@@ -17,13 +18,18 @@ class Collection {
17
18
return require ( './config.js' ) . default
18
19
}
19
20
static get components ( ) {
20
- const context = require . context ( "./components/" , true , / \. ( j s ) | ( v u e ) $ / ) ;
21
- return context . keys ( ) . reduce ( ( components , key ) => {
22
- const name = key . split ( '.vue' ) . shift ( ) . split ( '.js' ) . shift ( ) . split ( './' ) . pop ( )
23
- components [ name ] = context ( key ) . default ;
21
+ const context = require . context ( "./components/" , true , / \. ( j s ) | ( v u e ) $ / , 'lazy' ) ;
22
+ return context . keys ( ) . reduce ( ( components , path ) => {
23
+ const name = basename ( path , extname ( path ) )
24
+ const filename = basename ( path )
25
+ components [ name ] = ( ) => import ( `./components/${ filename } ` ) ;
24
26
return components
25
27
} , { } ) ;
26
28
}
29
+ static install ( Vue , options ) {
30
+ const components = Collection . components
31
+ Object . keys ( components ) . forEach ( key => Vue . component ( key , components [ key ] ) )
32
+ }
27
33
}
28
34
29
35
export default Collection
0 commit comments