Created
August 31, 2020 14:37
-
-
Save WisdomSky/b7c9bd0e29bf85927e9cfc300c6ffd44 to your computer and use it in GitHub Desktop.
Automatically registers all(except App.vue) vue components inside the components directory
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
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