Created
July 23, 2019 14:47
-
-
Save mulhoon/fadf19d042387c76eb4129b8e4e767d5 to your computer and use it in GitHub Desktop.
Global component loading in Vue
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
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