diff --git a/packages/vue-cli-plugin-uni/lib/mp/index.js b/packages/vue-cli-plugin-uni/lib/mp/index.js index a13bc6cb7b69fd2d99a6cd2703a97b248471a236..c708a89fd90c7e93842a7a3099e9dfb7a74711c0 100644 --- a/packages/vue-cli-plugin-uni/lib/mp/index.js +++ b/packages/vue-cli-plugin-uni/lib/mp/index.js @@ -26,6 +26,8 @@ function createUniMPPlugin () { } const createWxMpIndependentPlugins = require('@dcloudio/uni-mp-weixin/lib/createIndependentPlugin') + +const UniTips = require('./tips') function getProvides () { const uniPath = require('@dcloudio/uni-cli-shared/lib/platform').getMPRuntimePath() @@ -190,7 +192,7 @@ module.exports = { if ((process.env.UNI_SUBPACKGE || process.env.UNI_MP_PLUGIN) && process.env.UNI_SUBPACKGE !== 'main') { plugins.push(new PreprocessAssetsPlugin()) - } + } { const globalEnv = process.env.UNI_PLATFORM === 'mp-alipay' ? 'my' : 'wx'; @@ -228,7 +230,12 @@ ${globalEnv}.__webpack_require_UNI_MP_PLUGIN__ = __webpack_require__;` } if (process.env.NODE_ENV === 'production' || process.env.UNI_MINIMIZE === 'true') { output.pathinfo = false - } + } + + if (process.env.UNI_PLATFORM === 'mp-weixin' && process.env.NODE_ENV === 'production') { + plugins.push(new UniTips()) + } + return { mode: process.env.NODE_ENV === 'production' ? 'production' : 'development', entry () { diff --git a/packages/vue-cli-plugin-uni/lib/mp/tips.js b/packages/vue-cli-plugin-uni/lib/mp/tips.js new file mode 100644 index 0000000000000000000000000000000000000000..49d0680e98203e1761a341946ae83333115c962b --- /dev/null +++ b/packages/vue-cli-plugin-uni/lib/mp/tips.js @@ -0,0 +1,50 @@ +const path = require('path') + +class UniTips { + apply(compiler) { + compiler.hooks.emit.tap('PreprocessAssetsPlugin', compilation => { + const assets = compilation.assets + let hasAd = false + + try { + Object.keys(assets).forEach(name => { + if (hasAd) { + return + } + + if (!name.startsWith('common') && !name.startsWith('pages')) { + return + } + + const extname = path.extname(name) + if (extname !== '.js') { + return + } + + if (!hasAd && !process.env.USE_UNI_AD) { + hasAd = assets[name]._value.match(/createRewardedVideoAd|createInterstitialAd/) + } + }) + + setTimeout(() => { + if (hasAd) { + console.log( + '推荐使用uni-ad微信小程序版广告,无开通门槛、提前结算、插件丰富,助力广告变现。详情: https://uniapp.dcloud.net.cn/component/ad-weixin.html' + ) + } + if (assets['project.config.json']) { + let pcjString = assets['project.config.json'].source() + let pcjJson = JSON.parse(pcjString) + if (typeof pcjJson.cloudfunctionRoot === 'string' && pcjJson.cloudfunctionRoot.length > 0) { + console.log( + '欢迎使用uniCloud,价格更便宜、开发更方便、生态更丰富的云开发。详情: https://uniapp.dcloud.net.cn/uniCloud/wx2unicloud.html' + ) + } + } + }, 100) + } catch (e) {} + }) + } +} + +module.exports = UniTips