mp-weixin-uniad-app.json.js 1.3 KB
Newer Older
H
hdx 已提交
1 2
const UNI_PLUGINS = [{
  name: 'uni-ad',
3
  version: '1.2.1',
H
hdx 已提交
4 5 6 7
  provider: 'wxf72d316417b6767f'
},
{
  name: 'coral-adv',
8
  version: '1.0.24',
H
hdx 已提交
9 10 11 12
  provider: 'wx0e203209e27b1e66'
}
]

H
hdx 已提交
13
const {
H
hdx 已提交
14
  getManifestJson
H
hdx 已提交
15 16
} = require('@dcloudio/uni-cli-shared/lib/manifest.js')

H
hdx 已提交
17
module.exports = function (appJson, useAD) {
H
hdx 已提交
18 19 20 21 22 23 24 25 26 27 28 29
  const manifestJson = getManifestJson()
  const manifestJsonWxNode = manifestJson['mp-weixin']
  if (manifestJsonWxNode) {
    const plugins = manifestJsonWxNode.plugins || {}
    for (const key in plugins) {
      const provider = plugins[key].provider
      if (provider) {
        const exists = UNI_PLUGINS.find((item) => item.provider === provider)
        if (exists) {
          console.error('应用的uni-ad配置不正确,请直接在页面中引入uni-ad广告组件,无需单独引入插件。')
          process.exit(-1)
        }
H
hdx 已提交
30 31 32 33 34 35 36 37
      }
    }
  }

  if (!useAD) {
    return
  }

38 39 40
  if (!appJson.plugins) {
    appJson.plugins = {}
  }
H
hdx 已提交
41 42 43 44 45 46

  for (let i = 0; i < UNI_PLUGINS.length; i++) {
    const { name, version, provider } = UNI_PLUGINS[i]
    appJson.plugins[name] = {
      version,
      provider
47 48 49 50 51 52
    }
  }

  if (!appJson.usingComponents) {
    appJson.usingComponents = {}
  }
d-u-a's avatar
d-u-a 已提交
53 54
  if (!appJson.usingComponents['uniad-plugin']) {
    appJson.usingComponents['uniad-plugin'] = 'plugin://uni-ad/ad'
55 56
  }
}