Last active
February 10, 2020 11:31
-
-
Save jellehak/a78d9be4d07e72288306137033c8b90e to your computer and use it in GitHub Desktop.
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
// Globally register all base components for convenience, because they | |
// will be used very frequently. Components are registered using the filename | |
import Vue from 'vue'; | |
// https://webpack.js.org/guides/dependency-management/#require-context | |
const requireComponent = require.context( | |
'./', // Look for files in the current directory | |
true, // include subdirectories | |
// Only include "_base-" prefixed .vue files | |
// /_base-[\w-]+\.vue$/ | |
// /[\w-]+\.vue$/ | |
/\.vue$/ | |
); | |
// For each matching file name... | |
requireComponent.keys().forEach(fileName => { | |
// Get the component config | |
const componentConfig = requireComponent(fileName); | |
const componentName = | |
fileName | |
.replace(/^.*[\\/]/, '') // Remove path | |
.replace(/\.\w+$/, ''); // Remove extension | |
// Globally register the component | |
Vue.component(componentName, componentConfig.default || componentConfig); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment