registerComponents.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import Vue from "vue";
  2. // import upperFirst from "lodash/upperFirst";
  3. // import camelCase from "lodash/camelCase";
  4. const requireComponent = require.context(
  5. // The relative path of the components folder
  6. "./",
  7. // Whether or not to look in subfolders
  8. false,
  9. // The regular expression used to match base component filenames
  10. /[A-Z]\w+\.(vue|js)$/
  11. );
  12. requireComponent.keys().forEach((fileName) => {
  13. // Get component config
  14. const componentConfig = requireComponent(fileName);
  15. // Get PascalCase name of component
  16. const componentName =
  17. // upperFirst(
  18. // camelCase(
  19. // Gets the file name regardless of folder depth
  20. fileName
  21. .split("/")
  22. .pop()
  23. .replace(/\.\w+$/, "");
  24. // )
  25. // );
  26. // Register component globally
  27. Vue.component(
  28. componentName,
  29. // Look for the component options on `.default`, which will
  30. // exist if the component was exported with `export default`,
  31. // otherwise fall back to module's root.
  32. componentConfig.default || componentConfig
  33. );
  34. });