Skip to content

Instantly share code, notes, and snippets.

@tyom
Created November 12, 2018 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tyom/d7620cbb58861e30ed66a6a52de51591 to your computer and use it in GitHub Desktop.
Save tyom/d7620cbb58861e30ed66a6a52de51591 to your computer and use it in GitHub Desktop.
Import all Vue components that match regex as global
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