Skip to content

Instantly share code, notes, and snippets.

@jellehak
Last active February 10, 2020 11:31
Show Gist options
  • Save jellehak/a78d9be4d07e72288306137033c8b90e to your computer and use it in GitHub Desktop.
Save jellehak/a78d9be4d07e72288306137033c8b90e to your computer and use it in GitHub Desktop.
// 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