Skip to content

Instantly share code, notes, and snippets.

@8bu
Forked from Gkiokan/autoloadComponents.js
Created May 9, 2019 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 8bu/de8671787cfacda9b7cb0141a59878ca to your computer and use it in GitHub Desktop.
Save 8bu/de8671787cfacda9b7cb0141a59878ca to your computer and use it in GitHub Desktop.
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.name, Component)
}, {})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment