From 98642284a8e74e0a710d2af35762d4e843bddc09 Mon Sep 17 00:00:00 2001 From: Pierre Romera Date: Wed, 5 Dec 2018 14:20:25 +0100 Subject: [PATCH] Added install method --- docs/main.js | 5 +---- lib/main.js | 14 ++++++++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/docs/main.js b/docs/main.js index f44d41829..611947a51 100644 --- a/docs/main.js +++ b/docs/main.js @@ -23,15 +23,12 @@ Vue.use(VueRouter) Vue.use(VueClipboard) Vue.use(BootstrapVue) Vue.use(VueHighlightJS) +Vue.use(Collection) Vue.component('ApiTable', ApiTable) Vue.component('SampleCard', SampleCard) Vue.component('PalettePresenter', PalettePresenter) -Object.keys(Collection.components).forEach(key => { - Vue.component(key, Collection.components[key]) -}) - Collection.config.set('project.name', 'Demo Project') /* eslint-disable no-new */ diff --git a/lib/main.js b/lib/main.js index 98fe864d9..9fa919f9e 100644 --- a/lib/main.js +++ b/lib/main.js @@ -1,3 +1,4 @@ +import { basename, extname } from 'path' export { default as config } from './config' export { default as ContentPlaceholder } from './components/ContentPlaceholder.vue' export { default as DonateForm } from './components/DonateForm.vue' @@ -17,13 +18,18 @@ class Collection { return require('./config.js').default } static get components() { - const context = require.context("./components/", true, /\.(js)|(vue)$/); - return context.keys().reduce((components, key) => { - const name = key.split('.vue').shift().split('.js').shift().split('./').pop() - components[name] = context(key).default; + const context = require.context("./components/", true, /\.(js)|(vue)$/, 'lazy'); + return context.keys().reduce((components, path) => { + const name = basename(path, extname(path)) + const filename = basename(path) + components[name] = () => import(`./components/${filename}`); return components }, {}); } + static install (Vue, options) { + const components = Collection.components + Object.keys(components).forEach(key => Vue.component(key, components[key])) + } } export default Collection