Created
May 9, 2019 11:02
-
-
Save Gkiokan/3fbeb12bfc50072961389e202a040c97 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
for vue 3 use this