diff --git a/src/views/loadComponents.js b/src/views/loadComponents.js new file mode 100644 index 00000000..5e5cba2d --- /dev/null +++ b/src/views/loadComponents.js @@ -0,0 +1,27 @@ +'use strict' + +import upperFirst from 'lodash/upperFirst' +import camelCase from 'lodash/camelCase' + +const requireComponent = require.context( + '@/components', + false, + /Base[A-Z]\w+\.(vue|js)$/ +) + +export default function(Vue) { + requireComponent.keys().forEach(fileName => { + const componentConfig = requireComponent(fileName) + + const componentName = upperFirst( + camelCase(fileName + .split('/') + .pop() + .replace(/\.\w+$/, '') + ) + ) + + + Vue.component(componentName, componentConfig.default || componentConfig) +}) +}