Skip to content

Instantly share code, notes, and snippets.

@LSViana
Last active September 23, 2019 01:58
Show Gist options
  • Save LSViana/749c459dacb0b7b8c20d8825237a871f to your computer and use it in GitHub Desktop.
Save LSViana/749c459dacb0b7b8c20d8825237a871f to your computer and use it in GitHub Desktop.
Register all Vue components inside 'components' folder and children folders
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