十、vendor 798KB 的真正元凶:mp-weixin 开了 uni-push(2026-10-21 二次重建)
结果对照
| 第一次重建 | 第二次重建(easycom 修完) | |
|---|---|---|
| 主包 uview | 328KB | 277KB ✓(-51KB,负向前瞻生效) |
| vendor.js | 794KB | 783.5KB(几乎没动) |
| 主包 u-upload 目录 | 存在(死文件) | 不存在 ✓ |
定位过程(sourcemap 一击命中)
vendor 里查到一个陌生入口模块,特征:
SDK_VERSION = "GTMP-2.0.6"
DEFAULT_SOCKET_URL = "wss://wshzn.gepush.com:5223/nws"
setSocketServer / enableSocket / publicKeyId
gepush.com = 个推。但源码树 + node_modules 里 grep setSocketServer 全空。
最后从 unpackage/dist/dev/.sourcemap/mp-weixin/common/vendor.js.map 的 sources 里找到:
webpack:///./node_modules/@dcloudio/vue-cli-plugin-uni/packages/uni-push/dist/uni-push.es.js
→ 是 DCloud 官方 uni-push 模块,它内部 import CryptoJS from 'crypto-js' 全量,
这就是「改了半天按需引入、vendor 一点没降」的原因,也是最初统计里那个 188KB 的 c891 模块。
为什么可以关
manifest.json 的 mp-weixin 段里有:
"unipush" : { "enable" : true }
| 但全项目证据表明微信小程序端根本不用 uni-push: | 调用点 | 是否条件编译 |
|---|---|---|
App.vue:10-12 import uniPushListener |
#ifdef APP-PLUS ✓ |
|
App.vue:109-164 getInfo/getClientInfoLoop/pushListener |
#ifdef APP-PLUS ✓ |
|
pages/user/user/u-info.vue:187 uni.getPushClientId |
#ifdef APP-PLUS ✓ |
|
utils/ws.js:87,175 plus.push.* |
#ifdef APP-PLUS ✓ |
|
utils/checkUserLogin.js:408 plus.push.* |
#ifdef APP-PLUS ✓ |
小程序端订阅消息用的是微信原生 uni.requestSubscribeMessage(utils/util.js:2725),
跟 uni-push 模块无关。
改动
manifest.json → mp-weixin 段:
"unipush" : { "enable" : false } // 原为 true
(app-plus 段的 modules.Push 与 sdkConfigs.push.unipush 保持不动,App 端推送不受影响)
预期:vendor 783.5 → ~600KB(uni-push 运行时 + crypto-js 全量约 150–190KB)
⚠️ 注意
- 若将来小程序端要用「uni-push 微信订阅消息」,把
enable改回true。 - 服务端通过微信官方接口发订阅消息不受此开关影响,这个开关只决定前端是否打包 uni-push SDK。
- 验证:重建后
grep -c "gepush" common/vendor.js应为 0。
EOF
echo "=== 文档已更新 ==="
Ran terminal command: cd /Users/user/Documents/Important/uni2025 && git show HEAD:manifest.json > /tmp/m0.json 2>/dev/null && echo "=== 原始版本同样检查 ===" && node -e '
const fs=require("fs");
function chk(p,label){
let t=fs.readFileSync(p,"utf8");
t=t.replace(//*[\s\S]?*//g,"").replace(/^\s//.$/gm,"").replace(/"(?:[^"\]|\.)"/g,"""");
const c={"{":0,"}":0,"[":0,"]":0};
for(const ch of t){ if(ch in c) c[ch]++; }
console.log(label, "{:",c["{"],"} :",c["}"],"[ :",c["["],"] :",c["]"], c["{"]===c["}"]&&c["["]===c["]"]?"✓":"❌");
}
chk("/tmp/m0.json","原始: ");
chk("manifest.json","当前: ");
' && echo && echo "=== git diff 我改的部分 ===" && git diff -U3 manifest.json | head -30
Ran terminal command: cd /Users/user/Documents/Important/uni2025 && node -e '
const fs=require("fs");
function stats(p){
let t=fs.readFileSync(p,"utf8");
t=t.replace(//*[\s\S]?*//g,"").replace(/^[ \t]//.$/gm,"").replace(/"(?:[^"\]|\.)"/g,"""");
const c={"{":0,"}":0,"[":0,"]":0};
for(const ch of t){ if(ch in c) c[ch]++; }
return c;
}
const a=stats("/tmp/m0.json"),b=stats("manifest.json");
console.log("原始: {}=",a["{"],a["}"]," []=",a["["],a["]"], a["{"]===a["}"]&&a["["]===a["]"]?"✓":"❌");
console.log("当前: {}=",b["{"],b["}"]," []=",b["["],b["]"], b["{"]===b["}"]&&b["["]===b["]"]?"✓":"❌");
console.log("差值: {",b["{"]-a["{"],"}",b["}"]-a["}"],"[",b["["]-a["["],"]",b["]"]-a["]"]);
' && echo && echo "=== 当前 unipush 片段 ===" && sed -n '266,276p' manifest.json && echo && echo "=== git diff ===" && git diff --stat manifest.json
Updated memory file
主包 uview 这一部分已经生效:328 → 277KB,主包里 node-modules/uview-ui/components/u-upload/ 目录已不再生成。vendor 没降的真凶也找到了。
一、vendor 783KB 的真凶:mp-weixin 开了 uni-push
通过 sourcemap 链定位到的:
unpackage/dist/dev/.sourcemap/mp-weixin/common/vendor.js.map
→ webpack:///./node_modules/@dcloudio/vue-cli-plugin-uni/packages/uni-push/dist/uni-push.es.js
这个 uni-push 模块就是之前统计里那个 188KB 的 c891 模块,它内部 import CryptoJS from 'crypto-js' 是全量的,这就是你改了按需引入、vendor 却一点没降的原因。
为什么之前源码 grep 不到它:它不在你的源码里,它在 DCloud 的编译器包里(特征串 GTMP-2.0.6 / wss://wshzn.gepush.com = 个推)。
二、为什么可以关掉
manifest.json 的 mp-weixin 段有 "unipush": {"enable": true},但全项目 push 调用都在 App-only 条件编译里:
| 调用点 | 条件编译 |
|---|---|
App.vue:10-12 import uniPushListener |
#ifdef APP-PLUS ✓ |
App.vue:109-164 getInfo/pushListener |
#ifdef APP-PLUS ✓ |
u-info.vue:187 uni.getPushClientId |
#ifdef APP-PLUS ✓ |
utils/ws.js:87,175 plus.push.* |
#ifdef APP-PLUS ✓ |
utils/checkUserLogin.js:408 plus.push.* |
#ifdef APP-PLUS ✓ |
小程序端订阅消息走的是微信原生 uni.requestSubscribeMessage(utils/util.js:2725),跟 uni-push 模块无关。
已改:
"unipush" : {
"enable" : false // 原 true
},
app-plus 段的 modules.Push 和 sdkConfigs.push.unipush 没动,App 端推送不受影响。manifest 括号配平已校验(与 git HEAD 对比差值为 0)。
三、请再重建一次
预期:
| 现在 | 预期 | |
|---|---|---|
| vendor.js | 783.5KB | ~600KB |
| 主包 uview | 277KB | 277KB |
(你看到的 798 是 du 的磁盘块统计,实际字节 783.5KB)
重建后验证:
cd unpackage/dist/build/mp-weixin
grep -c "gepush" common/vendor.js # 期望 0
grep -c "Rabbit" common/vendor.js # 期望 0
stat -f%z common/vendor.js | awk '{printf "%.1f KB\n", $1/1024}'
如果 gepush 归零,说明 uni-push 彻底出去了,你的 crypto-js 按需引入才真正开始生效(那部分还能再省 ~40KB)。
⚠️ 一个前提要你确认:微信小程序端确实没有用 uni-push 的服务端推送。如果后端有通过 uni-push 向小程序推消息的逻辑,把 enable 改回 true 即可(这个开关只决定前端是否打包该 SDK,微信官方订阅消息接口不受影响)。
Made changes.
0 个评论
要回复文章请先登录或注册