参照相关文档,在package.json中配置electron-builder的基础打包设置:

  "build": {
    "productName": "Fishing Funds",
    "appId": "com.electron.1zilc.fishing-funds",
    "copyright": "Copyright © 2021 1zilc",
    "files": [
      "dist/",
      "node_modules/",
      "index.html",
      "main.prod.js",
      "main.prod.js.map",
      "package.json"
    ],
    "afterSign": ".erb/scripts/Notarize.js",
    "mac": {
      "target": [
        "dmg"
      ],
      "type": "distribution",
      "hardenedRuntime": true,
      "entitlements": "assets/entitlements.mac.plist",
      "entitlementsInherit": "assets/entitlements.mac.plist",
      "gatekeeperAssess": false
    },
    "dmg": {
      "contents": [
        {
          "x": 130,
          "y": 220
        },
        {
          "x": 410,
          "y": 220,
          "type": "link",
          "path": "/Applications"
        }
      ]
    },
    "win": {
      "target": [
        "nsis"
      ]
    },
    "linux": {
      "target": [
        "AppImage"
      ],
      "category": "Development"
    },
    "directories": {
      "app": "src",
      "buildResources": "assets",
      "output": "release"
    },
    "extraResources": [
      "./assets/**"
    ]
  },

在该配置的基础上添加 publish key,如下:

   "publish": {
      "provider": "github",
      "owner": "1zilc",
      "repo": "fishing-funds"
    }

以我自己的 Fishing Funds 为例

添加github token,网址如下: https://github.com/settings/tokens/new

勾选repo仓库相关权限

生成token后,临时添加环境变量中

export GH_TOKEN="<YOUR_TOKEN_HERE>"

在package.json中编写scripts,根据实际情况做调整

 "scripts": {
    "build": "concurrently \"yarn build:main\" \"yarn build:renderer\"",
    "build:main": "cross-env NODE_ENV=production webpack --config ./.erb/configs/webpack.config.main.prod.babel.js",
    "build:renderer": "cross-env NODE_ENV=production webpack --config ./.erb/configs/webpack.config.renderer.prod.babel.js",
    "package": "rm -rf src/dist && yarn build && electron-builder build --publish never",
    "package-mac": "rm -rf src/dist && yarn build && electron-builder build --mac -p always",
    "package-linux": "rm -rf src/dist && yarn build && electron-builder build --linux",
    "package-win": "rm -rf src/dist && yarn build && electron-builder build --win --x64",
    "package-all": "rm -rf src/dist && yarn build && electron-builder build -mwl",
    "release-all": "rm -rf src/dist && yarn build && electron-builder build -mwl --publish always"
  },
# 添加发布参数即release-all中所写
electron-builder build --publish always

执行

yarn release-all

构建完成后会自动通过刚才设置的token去调github的发布接口,此时仓库中会自动生成一个草稿状态的release,在填写相关日志后即可进行版本发布

electron-builder 自动发布 github release 到此完成! 🙂

发布结果:https://github.com/1zilc/fishing-funds

761 个评论

  1. Admiring the dedication you put into your site and detailed information you present.
    It’s nice to come across a blog every once in a while that isn’t
    the same outdated rehashed material. Great read! I’ve saved
    your site and I’m including your RSS feeds to my Google
    account.

  2. Greetings from Idaho! I’m bored to tears at work so I decided to check out your blog on my iphone during lunch break.
    I really like the knowledge you present here and can’t wait to take a look when I get home.
    I’m amazed at how fast your blog loaded on my cell phone ..
    I’m not even using WIFI, just 3G .. Anyhow, great site!

  3. You actually make it seem so easy with your presentation but I in finding
    this topic to be really one thing which I believe I would by no means understand.
    It kind of feels too complex and extremely vast for me.
    I am looking forward on your next put up, I will attempt to get
    the grasp of it!

  4. Woah! I’m really enjoying the template/theme of this site.
    It’s simple, yet effective. A lot of times it’s challenging to get that “perfect balance” between user friendliness and visual appearance.

    I must say you have done a awesome job with this. Also, the blog loads extremely quick for me
    on Chrome. Excellent Blog!

  5. Hey there would you mind letting me know which hosting company you’re
    working with? I’ve loaded your blog in 3 completely different web browsers and I
    must say this blog loads a lot quicker then most. Can you recommend
    a good hosting provider at a reasonable price? Cheers, I appreciate it!

  6. Magnificent beat ! I wish to apprentice whilst you amend your website, how could i
    subscribe for a weblog website? The account aided me a appropriate deal.
    I were tiny bit familiar of this your broadcast offered vibrant transparent concept

  7. Today, I went to the beach with my children. I found a sea shell and gave it to
    my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She placed the shell to her ear
    and screamed. There was a hermit crab inside and it pinched her ear.
    She never wants to go back! LoL I know this is completely off
    topic but I had to tell someone!

回复 lekekremi 取消回复

您的邮箱地址不会被公开。 必填项已用 * 标注