Skip to content

Commit 9864228

Browse files
committed
Added install method
1 parent ec8b69b commit 9864228

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

docs/main.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,12 @@ Vue.use(VueRouter)
2323
Vue.use(VueClipboard)
2424
Vue.use(BootstrapVue)
2525
Vue.use(VueHighlightJS)
26+
Vue.use(Collection)
2627

2728
Vue.component('ApiTable', ApiTable)
2829
Vue.component('SampleCard', SampleCard)
2930
Vue.component('PalettePresenter', PalettePresenter)
3031

31-
Object.keys(Collection.components).forEach(key => {
32-
Vue.component(key, Collection.components[key])
33-
})
34-
3532
Collection.config.set('project.name', 'Demo Project')
3633

3734
/* eslint-disable no-new */

lib/main.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { basename, extname } from 'path'
12
export { default as config } from './config'
23
export { default as ContentPlaceholder } from './components/ContentPlaceholder.vue'
34
export { default as DonateForm } from './components/DonateForm.vue'
@@ -17,13 +18,18 @@ class Collection {
1718
return require('./config.js').default
1819
}
1920
static get components() {
20-
const context = require.context("./components/", true, /\.(js)|(vue)$/);
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, /\.(js)|(vue)$/, '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}`);
2426
return components
2527
}, {});
2628
}
29+
static install (Vue, options) {
30+
const components = Collection.components
31+
Object.keys(components).forEach(key => Vue.component(key, components[key]))
32+
}
2733
}
2834

2935
export default Collection

0 commit comments

Comments
 (0)