build: 优化打包体积(compression maximum + afterPack 裁剪语言包)zip 139.7MB -> 128.9MB

This commit is contained in:
2026-08-23 11:23:57 +08:00
parent 2c90205766
commit 4b3ea03dc2
3 changed files with 65 additions and 0 deletions
+16
View File
@@ -178,3 +178,19 @@
- 核对确认:配置菜单 6 项(info/remote/shortcut/publish/device/about`configMenus.ts`)、发布 6 按钮顺序与指令清单一致、快捷键体系(1-9 长按阈值/↑↓/Esc/F5/锁定键)、AES-256-GCM 加密、settings.json 字段(lastDir 等)、Page 字段 9 项(含 PagePreview)。
- **未实现(写入文档规划)**:项目导入/导出、代码视图/页面视图切换、遥控器硬件对接、帮助文档入口。
- 交付:根目录 `项目需求` 文件已整体覆盖为新版;`指令清单` 未改动(其需求已全部实现,作为历史保留)。
## 2026-08-23 首次 commit + push
- 根目录创建 `.gitignore`(忽略 node_modules / SmartAgriCenter 的 out、dist、release / IDE / 日志);`SmartAgriCenter/.gitignore` 已存在并正确忽略构建产物。
- 首次提交 **68810be**main61 files14564 insertions):Electron 重写版全部源码、构建配置、图标、示例工程 json、prototype 原型、`项目需求`(v2.0)、`指令清单``.codebuddy/memory/`(记忆一并入仓备份)。
- 推送远程:**`DataViewCenter` = https://github.bbitcn.net/fanhongcai/DataViewCenter.git**(注意远程名是 `DataViewCenter`**不是 origin**`git push -u DataViewCenter main`)。上游已跟踪 `DataViewCenter/main`
- 环境备注:PowerShell 终端,`git -C` 参数含中文路径会乱码,需先在项目根目录再执行 git 命令;`credential-manager-core` 不是有效 git 命令(无害告警,凭据已缓存)。
## 2026-08-23 打包瘦身
- **问题**:用户反馈 zip 139.7MB 太大。构成:exeElectron 内核)224.6MB、dxcompiler.dll 24.4MB、LICENSES.chromium.html 19.4MB(合规文件勿删)、locales ~55 个语言包 ~55MB。
- **改动**`electron-builder.yml``compression: maximum` + `afterPack: ./scripts/afterPack.js`(新增脚本,裁剪 locales 只留 zh-CN/zh-TW/zh-HK/en-US;可选删除 dxcompiler/dxil 的开关默认关闭)。
- **结果**zip 139.7 → **128.9MB**win-unpacked 364.9 → **319.8MB**locales 55 → 3 个。dxcompiler 保留(用户选择保守)。若删 dxcompiler+dxil 可再省 ~22MB zip。
- **⚠️ 打包环境大坑(重要)**:CodeBuddy CN 注入的 `node-safe-delete-shim` 把 Node 的 `fs.rm`/PowerShell `Remove-Item` 劫持为"回收站批量删除守卫",删除大量文件时报错(中文用户名 `范先生` 路径乱码致守卫脚本 MODULE_NOT_FOUND)。**electron-builder 解压前必须删旧 win-unpacked → 必触发 → 打包失败**。而且失败后 `npm run dist` 的 node/electron-builder 进程**会挂死不退出、占用 release 文件**。
- **解法**:① 打包前用 `[System.IO.Directory]::Delete(...,$true)` 删掉整个 `release` 目录(.NET API 绕过钩子);② 若报"文件被占用",先 `Get-CimInstance Win32_Process | Where CommandLine -like '*SmartAgriCenter*'` 找到挂死的 npm/electron-builder 进程 `Stop-Process -Force`;③ 再删 release 重跑 `npm run dist`
- 首次打包成功是因为 release 当时不存在;此后只要 release 存在就会触发删除陷阱。**记住:每次打包前先 .NET 删 release**。