Created
November 12, 2018 14:06
-
-
Save tyom/d7620cbb58861e30ed66a6a52de51591 to your computer and use it in GitHub Desktop.
Import all Vue components that match regex as global
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
const requireComponent = require.context( | |
'~/components', // components dir | |
true, // recursive | |
/^(\.\/.*)*V[A-Z].+\.vue$/, // name regex | |
); | |
requireComponent.keys().forEach(fileName => { | |
let baseComponentConfig = requireComponent(fileName); | |
baseComponentConfig = baseComponentConfig.default || baseComponentConfig; | |
const baseComponentName = | |
baseComponentConfig.name || | |
fileName.replace(/^.+\//, '').replace(/\.\w+$/, ''); | |
Vue.component(baseComponentName, baseComponentConfig); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment