const requireComponent = require.context( './components', // 在当前目录下查找 true, // 遍历子文件夹 /\.vue$/ // 正则匹配 以 .vue结尾的文件 ) const privateComponents = [] requireComponent.keys().forEach(fileName => { const comp = requireComponent(fileName) if (comp.default.componentName) { let layoutConfigData = comp.default.layoutConfigData if (!layoutConfigData && comp.default.mixins) { const hasLayoutConfigData = comp.default.mixins.find(el => { return el.layoutConfigData }) if (hasLayoutConfigData) { layoutConfigData = hasLayoutConfigData.layoutConfigData } } privateComponents.push( { componentName: comp.default.componentName, name: comp.default.name, path: fileName.slice(1), layoutConfigData: layoutConfigData || [] } ) } }) export default privateComponents