index.js 912 Bytes
Newer Older
wangdanlei's avatar
wangdanlei committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
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