优化 Electron 打包体积:排除源码与冗余依赖

配置 electron-builder files 仅打 out 产物,移除未用依赖并将 Vue 生态移至 devDependencies;koffi 仅解包 win32_x64 并在 afterPack 裁剪;打包前清理旧 zip。
This commit is contained in:
24kycj
2026-06-03 11:24:13 +08:00
parent 75490d8647
commit 057285ed89
5 changed files with 155 additions and 357 deletions
+9
View File
@@ -14,6 +14,15 @@ const required = [
'opencv_world490d.dll'
]
const opencvRelease = path.join(nativeDir, 'opencv_world490.dll')
const opencvDebug = path.join(nativeDir, 'opencv_world490d.dll')
if (fs.existsSync(opencvRelease)) {
console.warn('提示: 检测到 opencv_world490.dll,生产环境建议用 Release 版替换 Debug 版 opencv_world490d.dll 以减小体积')
} else if (fs.existsSync(opencvDebug)) {
const mb = Math.round(fs.statSync(opencvDebug).size / 1024 / 1024)
console.warn(`提示: 当前使用 Debug 版 OpenCV (${mb} MB),可从 docs/API/lib 换 Release 版 opencv_world490.dll`)
}
const missing = required.filter((name) => !fs.existsSync(path.join(nativeDir, name)))
if (missing.length) {
console.error(`resources/native 缺少: ${missing.join(', ')}`)