@dcloudio/vue-cli-plugin-uni 2.0.2-alpha-5010220260529001 → 2.0.2-alpha-5010320260611001

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/env.js CHANGED
@@ -35,6 +35,9 @@ const {
35
35
  hasPushModule,
36
36
  isEnableSecureNetwork
37
37
  } = require('@dcloudio/uni-cli-shared/lib/manifest')
38
+ const {
39
+ resolveStatEnable
40
+ } = require('@dcloudio/uni-cli-shared/lib/stat')
38
41
 
39
42
  const manifestJsonObj = getManifestJson()
40
43
 
@@ -474,62 +477,132 @@ process.env.MERGE_VIRTUAL_HOST_ATTRIBUTES = (!!platformOptions.mergeVirtualHostA
474
477
  process.env.UNI_STATISTICS_CONFIG = '""'
475
478
  process.env.UNI_STAT_UNI_CLOUD = '""'
476
479
  process.env.UNI_STAT_DEBUG = '""'
480
+
481
+ const MP_WEIXIN_USE_PRELOAD_ASSETS_REPORT = true
482
+
483
+ /** 公有版小程序 GET 上报域名 */
484
+ const STAT_MP_REQUEST_DOMAIN = 'tongji-collector.dcloud.net.cn'
485
+ const STAT_MP_DOMAIN_DOC_URL = 'https://uniapp.dcloud.net.cn/uni-stat-public.html'
486
+ const STAT_WARN_NO_APPID =
487
+ '当前应用未配置 appid,无法使用 uni 统计,详情参考:https://ask.dcloud.net.cn/article/36303'
488
+ const STAT_PRIVATE_ANDROID_WARN =
489
+ '【重要】因 HBuilderX 3.4.9 版本起,uni统计2.0 调整了安卓端 deviceId 获取方式,导致 uni统计2.0 App-Android平台部分统计数据不准确。如使用了HBuilderX 3.4.9 - 3.6.4版本且开通了uni统计2.0的应用,需要使用HBuilderX3.6.7及以上版本重新发布应用并升级 uniAdmin 云函数解决,详见:https://ask.dcloud.net.cn/article/40097'
490
+
491
+ /**
492
+ * 解析 manifest.uniStatistics 的统计类型。
493
+ * 优先 type(public/private);缺失或非法时回退 version(2=private,其余=public)。
494
+ */
495
+ function resolveUniStatType (uniStatistics) {
496
+ const type = String(uniStatistics.type || '').trim()
497
+ if (type === 'public' || type === 'private') {
498
+ return type
499
+ }
500
+ return Number(uniStatistics.version) === 2 ? 'private' : 'public'
501
+ }
502
+
503
+ /**
504
+ * 是否应向 main 入口自动 import 统计运行时。
505
+ * uni-app x 暂不自动 import;enable 按子→根→默认(true) 三级规则解析。
506
+ */
507
+ function shouldAutoImportStatRuntime (rootStat, platformStat) {
508
+ if (process.env.UNI_APP_X === 'true') {
509
+ return false
510
+ }
511
+ return resolveStatEnable(rootStat, platformStat)
512
+ }
513
+
514
+ /** 构建期统计提示输出(与 uni-stat vite 插件 uniStatLog 一致) */
515
+ function uniStatLog (text) {
516
+ console.log()
517
+ console.warn(text)
518
+ console.log()
519
+ }
520
+
521
+ /** uni 统计 2.0 构建期「已开启」基础文案 */
522
+ const STAT_ENABLED_TIP_BASE = '已开启 uni统计 2.0'
523
+
524
+ /**
525
+ * 构建期「统计已开启」简短提示。
526
+ * public → 已开启uni 统计 2.0;private → 已开启uni 统计 2.0(私有版)
527
+ */
528
+ function formatStatEnabledTip (statType) {
529
+ if (statType === 'private') {
530
+ return `${STAT_ENABLED_TIP_BASE}(私有版)`
531
+ }
532
+ return STAT_ENABLED_TIP_BASE
533
+ }
534
+
535
+ /** 小程序公有版 request 合法域名提示(合并「已开启」与域名说明) */
536
+ function formatMpStatDomainTip () {
537
+ return `${STAT_ENABLED_TIP_BASE},为保障数据正常上报,请在小程序后台配置 request 合法域名:${STAT_MP_REQUEST_DOMAIN}。详情:${STAT_MP_DOMAIN_DOC_URL}`
538
+ }
539
+
540
+ /**
541
+ * 是否需要在构建期提示配置小程序 request 合法域名。
542
+ * 微信默认 preload 信标不走 uni.request,无需配置;开关关闭时与其它小程序一致。
543
+ */
544
+ function shouldShowMpDomainTip (platform, statType) {
545
+ if (statType !== 'public' || !platform.startsWith('mp-')) {
546
+ return false
547
+ }
548
+ if (platform === 'mp-weixin' && MP_WEIXIN_USE_PRELOAD_ASSETS_REPORT) {
549
+ return false
550
+ }
551
+ return true
552
+ }
553
+
554
+ /** 输出构建期「统计已开启」提示 */
555
+ function logStatEnabledTip (platform, statType) {
556
+ if (shouldShowMpDomainTip(platform, statType)) {
557
+ uniStatLog(formatMpStatDomainTip())
558
+ return
559
+ }
560
+ uniStatLog(formatStatEnabledTip(statType))
561
+ }
562
+
477
563
  if (
478
564
  process.env.UNI_USING_COMPONENTS ||
479
565
  process.env.UNI_PLATFORM === 'h5'
480
566
  ) { // 自定义组件模式或 h5 平台
567
+ const rootStat = manifestJsonObj.uniStatistics
568
+ const platformStat = platformOptions.uniStatistics
481
569
  const uniStatistics = Object.assign(
482
- manifestJsonObj.uniStatistics || {},
483
- platformOptions.uniStatistics || {}
570
+ {},
571
+ rootStat || {},
572
+ platformStat || {}
484
573
  )
485
574
 
486
- if (uniStatistics.enable === true) {
487
- const uniStatLog = (text) => {
488
- console.log()
489
- console.warn(text)
490
- console.log()
491
- }
492
- const version = Number(uniStatistics.version) === 2 ? '2' : '1'
493
- process.env.UNI_USING_STAT = version
494
- // 获取服务空间配置信息
495
- const uniCloudConfig = uniStatistics.uniCloud || {}
496
- process.env.UNI_STATISTICS_CONFIG = JSON.stringify(uniStatistics)
497
- process.env.UNI_STAT_UNI_CLOUD = JSON.stringify(uniCloudConfig)
498
- process.env.UNI_STAT_DEBUG = uniStatistics.debug === true ? 'true' : 'false'
575
+ // 始终注入完整 manifest.uniStatisticsenable 仅控制是否自动 import
576
+ process.env.UNI_STATISTICS_CONFIG = JSON.stringify(uniStatistics)
577
+ process.env.UNI_STAT_DEBUG = uniStatistics.debug === true ? 'true' : 'false'
578
+
579
+ if (shouldAutoImportStatRuntime(rootStat, platformStat)) {
580
+ const statType = resolveUniStatType(uniStatistics)
581
+ const platform = process.env.UNI_PLATFORM
582
+ let autoImport = true
499
583
 
500
584
  if (process.env.NODE_ENV === 'production') {
501
585
  if (!process.UNI_STAT_CONFIG.appid) {
502
- uniStatLog(uniI18n.__('pluginUni.uniStatisticsNoAppid', {
503
- 0: 'https://ask.dcloud.net.cn/article/36303'
504
- }))
586
+ uniStatLog(STAT_WARN_NO_APPID)
587
+ autoImport = false
505
588
  } else {
506
- if (!uniStatistics.version) {
507
- uniStatLog(uniI18n.__('pluginUni.uniStatisticsNoVersion', {
508
- 0: 'https://uniapp.dcloud.io/uni-stat-v2.html'
509
- }))
510
- } else {
511
- uniStatLog(`已开启 uni统计${uniStatistics.version}.0 版本`)
512
- if (version === '2') {
513
- uniStatLog(
514
- '【重要】因 HBuilderX 3.4.9 版本起,uni统计2.0 调整了安卓端 deviceId 获取方式,导致 uni统计2.0 App-Android平台部分统计数据不准确。如使用了HBuilderX 3.4.9 - 3.6.4版本且开通了uni统计2.0的应用,需要使用HBuilderX3.6.7及以上版本重新发布应用并升级 uniAdmin 云函数解决,详见:https://ask.dcloud.net.cn/article/40097'
515
- )
516
- }
589
+ logStatEnabledTip(platform, statType)
590
+ if (statType === 'private') {
591
+ uniStatLog(STAT_PRIVATE_ANDROID_WARN)
517
592
  }
518
593
  }
519
594
  } else {
520
- if (!uniStatistics.version) {
521
- uniStatLog(uniI18n.__('pluginUni.uniStatisticsNoVersion', {
522
- 0: 'https://uniapp.dcloud.io/uni-stat-v2.html'
523
- }))
524
- } else {
525
- uniStatLog(`已开启 uni统计${uniStatistics.version}.0 版本`)
526
- if (version === '2') {
527
- uniStatLog(
528
- '【重要】因 HBuilderX 3.4.9 版本起,uni统计2.0 调整了安卓端 deviceId 获取方式,导致 uni统计2.0 App-Android平台部分统计数据不准确。如使用了HBuilderX 3.4.9 - 3.6.4版本且开通了uni统计2.0的应用,需要使用HBuilderX3.6.7及以上版本重新发布应用并升级 uniAdmin 云函数解决,详见:https://ask.dcloud.net.cn/article/40097'
529
- )
530
- }
595
+ logStatEnabledTip(platform, statType)
596
+ if (statType === 'private') {
597
+ uniStatLog(STAT_PRIVATE_ANDROID_WARN)
531
598
  }
532
599
  }
600
+
601
+ if (autoImport) {
602
+ process.env.UNI_USING_STAT = statType
603
+ const uniCloudConfig = uniStatistics.uniCloud || {}
604
+ process.env.UNI_STAT_UNI_CLOUD = JSON.stringify(uniCloudConfig)
605
+ }
533
606
  }
534
607
  }
535
608
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/vue-cli-plugin-uni",
3
- "version": "2.0.2-alpha-5010220260529001",
3
+ "version": "2.0.2-alpha-5010320260611001",
4
4
  "description": "uni-app plugin for vue-cli 3",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -17,7 +17,7 @@
17
17
  "author": "fxy060608",
18
18
  "license": "Apache-2.0",
19
19
  "dependencies": {
20
- "@dcloudio/uni-stat": "^2.0.2-alpha-5010220260529001",
20
+ "@dcloudio/uni-stat": "^2.0.2-alpha-5010320260611001",
21
21
  "buffer-json": "^2.0.0",
22
22
  "clone-deep": "^4.0.1",
23
23
  "cross-env": "^5.2.0",
@@ -41,5 +41,5 @@
41
41
  "copy-webpack-plugin": ">=5",
42
42
  "postcss": ">=7"
43
43
  },
44
- "gitHead": "6480c1135660f0bceac8109422bb4e551d16d1b1"
44
+ "gitHead": "4bd2647dc8989047700b1643a943316144b1befa"
45
45
  }
@@ -47,9 +47,12 @@ module.exports = [
47
47
  },
48
48
  transform(code, id) {
49
49
  if (isEnable && opts.filter(id)) {
50
+ const importPath = process.env.UNI_USING_STAT === 'private'
51
+ ? '@dcloudio/uni-stat/dist/uni-cloud-stat.es.js'
52
+ : '@dcloudio/uni-stat/dist/uni-stat-public.es.js'
50
53
  return {
51
- code: code + `;import '@dcloudio/uni-stat';`,
52
- map: null,
54
+ code: code + `;import '${importPath}';`,
55
+ map: null
53
56
  }
54
57
  }
55
58
  },