From 94ee72224567777c9b567c5fdd48cfe8c417fad0 Mon Sep 17 00:00:00 2001 From: kPherox Date: Mon, 8 Apr 2019 05:08:14 +0900 Subject: [PATCH] Create base components loader --- src/views/loadComponents.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/views/loadComponents.js 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) +}) +}