使用electron-builder打包mac應(yīng)用后,無(wú)法安裝提示未認(rèn)證憔鬼,在不提交appstore時(shí)吉嚣,可以使用dmg認(rèn)證,官方文檔
- 使用蘋果開發(fā)者賬號(hào)生成develop-application類型證書炒嘲,導(dǎo)出p12
- 在.zshrc文件中加入以下內(nèi)容宇姚,配置證書信息
# electron builder CSC
export CSL_LINCSC_IDENTITY_AUTO_DISCOVERY=false
export CSC_LINK=/Users/xxx/mac-application.p12
export CSC_KEY_PASSWORD=xxxxxxx
- 項(xiàng)目?jī)?nèi)加入配置
"build": {
"productName": "測(cè)試",
"appId": "com.xx.xx",
"directories": {
"output": "release/${version}"
},
"files": [
"dist",
"electron"
],
"afterSign": "notarize.js",
"dmg": {
"sign": false,
"contents": [
{
"x": 410,
"y": 150,
"type": "link",
"path": "/Applications"
},
{
"x": 130,
"y": 150,
"type": "file"
}
]
},
}
# notarize.js
const { notarize } = require('@electron/notarize');
exports.default = async function notarizing(context) {
const { electronPlatformName, appOutDir } = context;
if (electronPlatformName !== 'darwin') {
return;
}
const appName = context.packager.appInfo.productFilename;
return await notarize({
appPath: `${appOutDir}/${appName}.app`,
keychainProfile: 'xxxxx'
});
};
- 打包完成后的信息
electron-builder version=24.9.1 os=22.6.0
? loaded configuration file=package.json ("build" field)
? writing effective config file=release/1.0.4/builder-effective-config.yaml
? packaging platform=darwin arch=x64 electron=21.4.4 appOutDir=release/1.0.4/mac
? signing file=release/1.0.4/mac/測(cè)試.app identityName=Developer ID Application: The Sixth identityHash=xxxxx provisioningProfile=none
? building target=macOS zip arch=x64 file=release/1.0.4測(cè)試-1.0.4-mac.zip
? building target=DMG arch=x64 file=release/1.0.4/測(cè)試-1.0.4.dmg
? building block map blockMapFile=release/1.0.4/測(cè)試-1.0.4.dmg.blockmap
? building block map blockMapFile=release/1.0.4/測(cè)試-1.0.4-mac.zip.blockmap
- 認(rèn)證完成