我可以在電子 package.json 中使用環境變量來獲取 osx 公證憑證嗎? (Can I use environment variables in electron package.json for osx notarize credentials?)


問題描述

我可以在電子 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 sychordCoderJ4Y‑M)

參考文件

  1. Can I use environment variables in electron package.json for osx notarize credentials? (CC BY‑SA 2.5/3.0/4.0)

#electron-packager #electron-notarize #electron-forge #code-signing






相關問題

哪個數據庫更適合用於電子窗口構建 (Which database is better to use with electron windows build)

使用 Electron Rebuilt 的 Electron Packager 腳本錯誤 (Electron Packager Script Error using Electron Rebuilt)

我可以在電子 package.json 中使用環境變量來獲取 osx 公證憑證嗎? (Can I use environment variables in electron package.json for osx notarize credentials?)

npm run make 在電子鍛造中不起作用 (npm run make is not working in electron-forge)

如何增加 window.localStorage 中限制的 ELECTRON 文件大小的大小限制? (How to increase the size limit of ELECTRON file size which is limited in window.localStorage?)

我應該如何排除電子打包器中的所有 node_modules (How should i exclude all node_modules in electron-packager)

如何在沒有互聯網的情況下離線運行電子包裝器? (How to run electron-packager offline without internet?)







留言討論