Created
June 27, 2019 13:55
-
-
Save skalibog/1869e85a9102c12fa1170a6debb72bf1 to your computer and use it in GitHub Desktop.
auto import global components
This file contains hidden or 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' | |
import upperFirst from 'lodash/upperFirst' | |
import camelCase from 'lodash/camelCase' | |
const requireComponent = require.context( | |
'@/components', true, /\.vue$/ | |
) | |
requireComponent.keys().forEach(fileName => { | |
const componentConfig = requireComponent(fileName) | |
const componentName = upperFirst( | |
camelCase(fileName.replace(/^\.\//, '').replace(/\.\w+$/, '')) | |
) | |
Vue.component(componentName, componentConfig.default || componentConfig) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment