Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. import Vue from 'vue'
  2.  
  3. import { upperFirstLetter } from './utils/string.extensions'
  4.  
  5. /** List all files from folder name. */
  6. let requireComponent = require.context(
  7. './components',
  8. // Consider subfolders?
  9. true,
  10. // The regular expression used to match base component filenames
  11. /[A-Z]\w+\.(vue|js|ts)$/
  12. )
  13.  
  14. /** Iterate keys. */
  15. requireComponent.keys().forEach(fileName => {
  16. /** Require the component. */
  17. const componentConfig = requireComponent(fileName);
  18.  
  19. /** Remove ./ and file extension. */
  20. let componentName = fileName.replace(/^\.\/(.*)\.\w+$/, '$1')
  21. componentName = componentName.split('/').pop() || "";
  22.  
  23. /** Register component. */
  24. Vue.component(
  25. upperFirstLetter(componentName),
  26. componentConfig.default || componentConfig
  27. )
  28. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement