-
-
Save 8bu/de8671787cfacda9b7cb0141a59878ca to your computer and use it in GitHub Desktop.
Autoload *.vue files as Component and register them
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Autoload all current vue files as component and register them by their name. | |
--- | |
Author: Gkiokan Sali | |
Date: 2019-05-09 | |
*/ | |
import Vue from 'vue' | |
const requireContext = require.context('./', false, /.*\.vue$/) | |
const layouts = requireContext.keys() | |
.map(file => | |
[file.replace(/(^.\/)|(\.vue$)/g, ''), requireContext(file)] | |
) | |
.reduce((components, [name, component]) => { | |
let Component = component.default || component | |
Vue.component(Component.name, Component) | |
}, {}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment