問題描述
我可以在電子 package.json 中使用環境變量來獲取 osx 公證憑證嗎? (Can I use environment variables in electron package.json for osx notarize credentials?)
成功公證了我的 osx 電子應用程序,但現在的問題是 apple id 和應用程序特定密碼在 package.json 中。我當然不想在那裡對它們進行硬編碼以進行分發,但是我可以使用 .env 文件中的環境變量來替換它們,或者如何在 package.json 文件中保密?
我查看了 dotenv 和 cross‑env,但沒有看到如何在 package.json 文件中使用 env 變量。
應用程序是使用電子鍛造構建的。
結構(取自 electron‑forge 文檔)我使用的:
{
"name": "my‑app",
"version": "0.0.1",
"config": {
"forge": {
"packagerConfig": {
"osxSign": {
"identity": "Developer ID Application: Felix Rieseberg (LT94ZKYDCJ)",
"hardened‑runtime": true,
"entitlements": "entitlements.plist",
"entitlements‑inherit": "entitlements.plist",
"signature‑flags": "library"
},
"osxNotarize": {
"appleId": "felix@felix.fun",
"appleIdPassword": "my‑apple‑id‑password",
}
}
}
}
}
提前致謝。
參考解法
方法 1:
Duplicate of your own post : Where can I find electron forge config js file where package.json is parsed?
You should rather extract the electron forge configuration in a separate JS file : ElectronForge configuration and load your environment variables using process.env.YOUR_VARIABLE_NAME
package.json
{
"name": "app",
"description": "app",
"productName": "app",
"version": "0.0.0",
"private": true,
"scripts": {
},
"config": {
"forge": "./forge.config.js"
},
...
}
forge.config.js
module.exports = {
"packagerConfig": {
"osxSign": {
"identity": "Developer ID Application: Felix Rieseberg (LT94ZKYDCJ)",
"hardened‑runtime": true,
"entitlements": "entitlements.plist",
"entitlements‑inherit": "entitlements.plist",
"signature‑flags": "library"
},
"osxNotarize": {
"appleId": process.env.NOTORIZE_APPLE_ID,
"appleIdPassword": process.env.NOTORIZE_APPLE_ID,
}
}
}
(by sychordCoder、J4Y‑M)