name: electron-builder-config description: 为多平台桌面构建生成和验证electron-builder配置,包括代码签名、自动更新和平台特定打包 allowed-tools: Read, Write, Edit, Bash, Glob, Grep tags: [electron, desktop, build, packaging, cross-platform]
electron-builder-config
为多平台桌面构建生成和验证electron-builder配置。此技能处理完整的配置,用于在Windows、macOS和Linux上构建Electron应用程序,包括适当的代码签名、自动更新通道和平台特定安装程序。
能力
- 生成完整的
electron-builder.yml或electron-builder.json5配置 - 配置平台特定的构建目标(NSIS、DMG、AppImage、DEB、RPM、Snap、Flatpak)
- 为Windows(Authenticode)和macOS(Developer ID)设置代码签名
- 使用electron-updater配置自动更新设置
- 通过压缩和去重优化构建产物
- 验证现有配置的常见问题
- 为GitHub Actions、Azure DevOps、CircleCI生成CI/CD构建脚本
输入模式
{
"type": "object",
"properties": {
"projectPath": {
"type": "string",
"description": "Electron项目根目录路径"
},
"appInfo": {
"type": "object",
"properties": {
"appId": { "type": "string", "description": "应用程序包ID(com.company.app)" },
"productName": { "type": "string" },
"copyright": { "type": "string" }
},
"required": ["appId", "productName"]
},
"platforms": {
"type": "array",
"items": { "enum": ["windows", "macos", "linux"] },
"description": "要构建的目标平台"
},
"targets": {
"type": "object",
"properties": {
"windows": { "type": "array", "items": { "enum": ["nsis", "nsis-web", "portable", "appx", "msi", "squirrel"] } },
"macos": { "type": "array", "items": { "enum": ["dmg", "pkg", "mas", "mas-dev", "zip"] } },
"linux": { "type": "array", "items": { "enum": ["AppImage", "deb", "rpm", "snap", "flatpak", "tar.gz"] } }
}
},
"codeSigning": {
"type": "object",
"properties": {
"windows": {
"type": "object",
"properties": {
"enabled": { "type": "boolean" },
"certificateSubjectName": { "type": "string" },
"timestampServer": { "type": "string" }
}
},
"macos": {
"type": "object",
"properties": {
"enabled": { "type": "boolean" },
"identity": { "type": "string" },
"hardenedRuntime": { "type": "boolean", "default": true },
"notarize": { "type": "boolean" }
}
}
}
},
"autoUpdate": {
"type": "object",
"properties": {
"enabled": { "type": "boolean" },
"provider": { "enum": ["github", "s3", "generic", "spaces", "keygen"] },
"channel": { "enum": ["latest", "beta", "alpha"] }
}
},
"generateCIScripts": {
"type": "boolean",
"description": "生成CI/CD构建脚本"
}
},
"required": ["projectPath", "appInfo", "platforms"]
}
输出模式
{
"type": "object",
"properties": {
"success": { "type": "boolean" },
"configPath": { "type": "string", "description": "生成配置文件的路径" },
"config": { "type": "object", "description": "生成的electron-builder配置" },
"ciScripts": {
"type": "array",
"items": {
"type": "object",
"properties": {
"path": { "type": "string" },
"description": { "type": "string" }
}
}
},
"warnings": { "type": "array", "items": { "type": "string" } },
"recommendations": { "type": "array", "items": { "type": "string" } }
},
"required": ["success"]
}
使用说明
- 分析项目结构:检查package.json、现有构建配置和项目布局
- 确定构建需求:基于目标平台和分发需求
- 生成配置:创建包含所有必要设置的electron-builder.yml
- 验证配置:检查常见问题和缺失依赖
- 生成CI脚本:如果请求,创建GitHub Actions或其他CI工作流
配置模板
基本多平台构建
appId: com.example.myapp
productName: MyApp
directories:
buildResources: build
output: dist
files:
- "**/*"
- "!**/*.{md,txt}"
- "!**/node_modules/*/{CHANGELOG.md,README.md,readme.md}"
win:
target:
- target: nsis
arch: [x64, ia32]
icon: build/icon.ico
mac:
target:
- target: dmg
arch: [x64, arm64]
icon: build/icon.icns
hardenedRuntime: true
gatekeeperAssess: false
linux:
target:
- target: AppImage
arch: [x64]
- target: deb
arch: [x64]
icon: build/icons
category: Utility
包含代码签名和公证
win:
sign: ./scripts/sign.js
signingHashAlgorithms: [sha256]
signDlls: true
mac:
identity: "Developer ID Application: Company Name (TEAMID)"
hardenedRuntime: true
entitlements: build/entitlements.mac.plist
entitlementsInherit: build/entitlements.mac.plist
afterSign: scripts/notarize.js
包含自动更新
publish:
provider: github
owner: your-org
repo: your-repo
releaseType: release
nsis:
oneClick: false
perMachine: true
allowToChangeInstallationDirectory: true
differentialPackage: true
最佳实践
- 始终使用
hardenedRuntime: true以通过macOS公证 - 启用
signingHashAlgorithms: [sha256]以获得现代Windows兼容性 - 使用
differentialPackage: true实现高效的自动更新 - 配置
files模式 以排除不必要的文件并减少包大小 - 设置单独的通道(latest、beta、alpha)用于分阶段发布
- 将签名凭据存储在CI机密中,切勿存储在配置文件中
社区参考
相关技能
electron-main-preload-generator- 生成安全的主进程和预加载脚本electron-auto-updater-setup- 配置具有高级功能的electron-updaterwindows-authenticode-signer- 使用signtool进行Windows代码签名macos-codesign-workflow- macOS代码签名和公证
相关代理
electron-architect- Electron架构和最佳实践专家desktop-ci-architect- 桌面构建的CI/CD流水线设计