使用电容器社区/电子通过安装程序创建桌面应用程序,但缺少安装程序

分享于2022年10月08日 angular capacitor electron ionic-framework package.json 问答
【问题标题】:using capacitor-community/electron to create desktop app with an installer, but installer missing使用电容器社区/电子通过安装程序创建桌面应用程序,但缺少安装程序
【发布时间】:2022-07-06 12:50:55
【问题描述】:

我创建了一个具有离子角度的应用程序。我正在尝试使用电子构建它并为该应用程序创建一个安装程序。 我已经运行 ionic build -> npm i @capacitor-community/electron --save-dev -> npx cap add @capacitor-community/electron

在创建的电子文件夹中,我添加了一些代码到 package.json

{
  "name": "financeapp",
  "productName":"Finance Monitor",
  "version": "1.0.0",
  "description": "An Amazing Capacitor App",
  "author": {
    "name": "",
    "email": ""
  },
  "repository": {
    "type": "git",
    "url": ""
  },
  "license": "MIT",
  "main": "build/src/index.js",
  "scripts": {
    "build": "tsc && electron-rebuild",
    "electron:start-live": "node ./live-runner.js",
    "electron:start": "npm run build && electron --inspect=5858 ./",
    "electron:pack": "npm run build && electron-builder build --dir -c ./electron-builder.config.json",
    "electron:make": "npm run build && electron-builder build -c ./electron-builder.config.json -p always"

  },
  "dependencies": {
    "@capacitor-community/electron": "^4.1.0",
    "chokidar": "~3.5.2",
    "electron-is-dev": "~2.0.0",
    "electron-serve": "~1.1.0",
    "electron-unhandled": "~3.0.2",
    "electron-updater": "~4.3.9",
    "electron-window-state": "~5.0.3"
  },
  "devDependencies": {
    "electron": "^14.0.0",
    "electron-builder": "~22.11.7",
    "electron-rebuild": "^3.2.3",
    "typescript": "~4.3.5"
  },
  "keywords": [
    "capacitor",
    "electron"
  ]
}


我的 electron-builder.config.json :

{
  "appId": "com.yourdoamnin.yourapp",
  "directories": {
    "buildResources": "resources"
  },
  "files": [
    "assets/**/*",
    "build/**/*",
    "capacitor.config.*",
    "app/**/*"
  ],
  "publish": {
    "provider": "github",
    "publishAutoUpdate": false
  },
  "nsis": {
    "allowElevation": true,
    "oneClick": false,
    "allowToChangeInstallationDirectory": true
  },
  "win": {
    "target": "nsis",
    "icon": "assets/appIcon.ico"
  },
  "mac": {
    "category": "your.app.category.type",
    "target": "dmg"
  }
}

然后我转到电子文件夹目录并运行: npm run electron:make ,但它只创建了一个没有安装程序的 win_unpack 文件夹并显示此错误:

 ⨯ Cannot detect repository by .git/config. Please specify "repository" in the package.json (https://docs.npmjs.com/files/package.json#repository).
Please see https://electron.build/configuration/publish  failedTask=build stackTrace=Error: Cannot detect repository by .git/config. Please specify "repository" in the package.json (https://docs.npmjs.com/files/package.json#repository).

我在这里做错了什么?如何创建安装程序?

  • 我发现了问题,它与 package.json 中存储库下的 url 有关。但是由于我在 github 中没有存储库,如何删除此存储库?

【解决方案1】:

Capacitor 3 @capacitor-community/electron 内置发布功能,如果使用 Github,希望您指定一个 repo 并添加一个 GITHUB_TOKEN。如果您不希望它自动发布,只需从 electron-builder.config.json 中删除发布部分。它从第 12 行左右开始。

【讨论】: