Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Autoload *.vue files as Component and register them
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)
}, {})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment