Skip to content

Instantly share code, notes, and snippets.

@WisdomSky
Created August 31, 2020 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WisdomSky/b7c9bd0e29bf85927e9cfc300c6ffd44 to your computer and use it in GitHub Desktop.
Save WisdomSky/b7c9bd0e29bf85927e9cfc300c6ffd44 to your computer and use it in GitHub Desktop.
Automatically registers all(except App.vue) vue components inside the components directory
const components_req = require.context('./components', true, /^(.*\.(vue))[^.]*$/im);
const components = components_req.keys().reduce(function(acc, key){
const name = key.replace(/^.*\/([^\.]+)\.vue/,'$1');
if (name !== 'App') {
let comp = components_req(key);
acc[name] = comp.default && comp.__esModule ? comp.default : comp;
}
return acc;
}, {});
for (const name in components) {
if (components.hasOwnProperty(name)) {
Vue.component(name, components[name]);
}
}
new Vue({
...
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment