Skip to content

Instantly share code, notes, and snippets.

@Alexisvt
Created September 2, 2019 14:29
Show Gist options
  • Save Alexisvt/fddfb48dae123497ada8e103c09db057 to your computer and use it in GitHub Desktop.
Save Alexisvt/fddfb48dae123497ada8e103c09db057 to your computer and use it in GitHub Desktop.
Plugin that load all the Vue components stored in the components folder in Nuxt project
import _ from 'lodash'
import Vue from 'vue'
const components = require.context('@/components', false, /[A-Z]\w+\.(vue)$/)
_.forEach(components.keys(), (fileName) => {
const componentConfig = components(fileName)
const componentName = fileName
.split('/')
.pop()
.split('.')[0]
Vue.component(componentName, componentConfig.default || componentConfig)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment