code: function register(componentPath, tagName, cache) {
    if (typeof componentPath === 'object') {
      // 直接传入定义对象
      const definition = componentPath
  
      return jComponent.register(definition)
    }
  
    if (typeof componentPath !== 'string') {
      throw new Error('componentPath must be a string')
    }
  
    if (!tagName || typeof tagName !== 'string') {
      tagName = 'main' // 默认标签名
    }
  
    const oldLoad = nowLoad
    const component = nowLoad = {
      tagName,
      json: _.readJson(`${componentPath}.json`),
    }
  
    if (!component.json) {
      throw new Error(`invalid componentPath: ${componentPath}`)
    }
  
    // 先加载 using components
    const usingComponents = component.json.usingComponents || {}
    const usingComponentKeys = Object.keys(usingComponents)
    for (let i = 0, len = usingComponentKeys.length; i < len; i++) {
      const key = usingComponentKeys[i]
      const usingPath = path.join(path.dirname(componentPath), usingComponents[key])
      const id = register(usingPath, key, cache)
  
      usingComponents[key] = id
    }
  
    // 读取自定义组件的静态内容
    component.wxml = compile.getWxml(componentPath, cache.options, usingComponents)
    component.wxss = wxss.getContent(`${componentPath}.wxss`)
  
    // 执行自定义组件的 js
    _.runJs(componentPath)
  
    // 保存追加了已编译的 wxss
    cache.wxss.push(wxss.compile(component.wxss, {
      prefix: tagName,
      ...cache.options,
    }))
  
    nowLoad = oldLoad
  
    return component.id
  }
docs: 注册自定义组件