const context = require.context("./", true, /\.vue$/);
const cmps = {};
context.keys().forEach((key) => {
if (key.includes("components")) {
const component = context(key).default;
cmps[component.name] = component;
}
});
//
components: {
...cmps,
},
vue3中的动态加载
const modules = import.meta.globEager('./components/**/*.vue')
let COMAll = {}
Object.keys(modules).forEach((key) => {
if (key.includes('components')) {
const component = modules[key].default
COMAll[component.__name] = component
}
})