Last active
September 23, 2019 01:58
-
-
Save LSViana/749c459dacb0b7b8c20d8825237a871f to your computer and use it in GitHub Desktop.
Register all Vue components inside 'components' folder and children folders
This file contains 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 Vue from 'vue' | |
// Importing all components inside './components' folder | |
const req = require.context('./components/', true, /\.(js|vue)$/i); | |
req.keys().map(key => { | |
const fileNameKey = key.substr(key.lastIndexOf('/') + 1); | |
const name = fileNameKey.match(/\w+/)[0]; | |
return Vue.component(name, req(key).default) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment