Created
September 2, 2019 14:29
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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