Skip to content

Instantly share code, notes, and snippets.

@mulhoon
Created July 23, 2019 14:47
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 mulhoon/fadf19d042387c76eb4129b8e4e767d5 to your computer and use it in GitHub Desktop.
Save mulhoon/fadf19d042387c76eb4129b8e4e767d5 to your computer and use it in GitHub Desktop.
Global component loading in Vue
import Vue from 'vue'
const components = require.context('@/components', true, /[A-Z]\w+\.(vue)$/)
let keys = components.keys()
keys.forEach(fileName => {
const componentConfig = components(fileName)
const componentName = fileName
.split('/')
.pop()
.split('.')[0]
Vue.component(componentName, componentConfig.default || componentConfig)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment