Skip to content

Instantly share code, notes, and snippets.

@uno-de-piera
Created Dec 28, 2019
Embed
What would you like to do?
import Vue from 'vue'
import upperFirst from 'lodash/upperFirst'
import camelCase from 'lodash/camelCase'
const requireComponent = require.context(
// mapeamos el directorio src/components
'./components',
// Si debe buscar o no en subcarpetas
false,
// buscamos archivos que empiezan con Base y tienen la extensión .vue o .js
/Base[A-Z]\w+\.(vue|js)$/
)
requireComponent.keys().forEach(fileName => {
const componentConfig = requireComponent(fileName)
const componentName = upperFirst(
camelCase(
fileName.replace(/^\.\/(.*)\.\w+$/, '$1')
)
)
// Registramos el componente de forma global
Vue.component(
componentName,
componentConfig.default || componentConfig
)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment