Pages

Wednesday, 30 May 2018

electron-build 和 electron-builder

Free public electron-build-service is used to build Electron app for Linux on Windows. On macOS/Linux you can build Electron app for Windows locally, except Appx for Windows Store (in the future (feel free to file issue) electron-build-service will support Appx target).
You can use build servers — e.g. Travis to build macOS/Linux apps and AppVeyor to build Windows app.
By default build for current platform and current arch. Use CLI flags --mac, --win, --linux to specify platforms. And --ia32, --x64 to specify arch.
For example, to build app for MacOS, Windows and Linux:
electron-builder -mwl
Build performed in parallel, so, it is highly recommended to not use npm task per platform (e.g. npm run dist:mac && npm run dist:win32), but specify multiple platforms/targets in one build command. You don't need to clean dist output before build — output directory is cleaned automatically.

Sample .travis.yml to Build Electron App for macOS, Linux and Windows

See sample .travis.yml.

Sample appveyor.yml to Build Electron App for Windows

Use AppVeyor only if:
  • you need to build AppX,
  • or your app has native dependency and prebuilt binary is not provided.
Otherwise see above sample .travis.yml to build Windows on Linux using provided Docker image.
See sample appveyor.yml.

macOS

All required system dependencies (except rpm) will be downloaded automatically on demand on macOS 10.12+ (macOS Sierra). On Travis, please add osx_image: xcode9.0 (see above sample .travis.yml).
To build rpm: brew install rpm (brew).

Linux

You can use Docker to avoid installing system dependencies.
To build app in distributable format for Linux:
sudo apt-get install --no-install-recommends -y libopenjp2-tools
To build rpm: sudo apt-get install --no-install-recommends -y rpm (or sudo yum install rpm-build).
To build pacman: sudo apt-get install --no-install-recommends -y bsdtar.
To build snap: sudo apt-get install --no-install-recommends -y snapcraft.

To build app for Windows on Linux:

Docker (electronuserland/builder:wine) is recommended to avoid installing system dependencies.
  • Install Wine (2.0+ is required) — see WineHQ Binary Packages.
  • Install Mono (4.2+ is required) if you want to use Squirrel.Windows (NSIS, default target, doesn't require mono).

To build app in 32 bit from a machine with 64 bit:

sudo apt-get install --no-install-recommends -y gcc-multilib g++-multilib

Travis Linux

Trusty is required.
sudo: required
dist: trusty

Travis macOS

macOS 10.12+ is required.
osx_image: xcode9.0

Docker

To build Linux or Windows on any platform. You cannot build for Windows using Docker if you have native dependencies and native dependency doesn't use prebuild.
See example Docker usage on a CI server in the sample .travis.yml.

Build Electron App using Docker on a Local Machine

  1. Run docker container:
    docker run --rm -ti \
      --env-file <(env | grep -iE 'DEBUG|NODE_|ELECTRON_|YARN_|NPM_|CI|CIRCLE|TRAVIS_TAG|TRAVIS|TRAVIS_REPO_|TRAVIS_BUILD_|TRAVIS_BRANCH|TRAVIS_PULL_REQUEST_|APPVEYOR_|CSC_|GH_|GITHUB_|BT_|AWS_|STRIP|BUILD_') \
      --env ELECTRON_CACHE="/root/.cache/electron" \
      --env ELECTRON_BUILDER_CACHE="/root/.cache/electron-builder" \
      -v ${PWD}:/project \
      -v ${PWD##*/}-node-modules:/project/node_modules \
      -v ~/.cache/electron:/root/.cache/electron \
      -v ~/.cache/electron-builder:/root/.cache/electron-builder \
      electronuserland/builder:wine
    
  2. Type in yarn && yarn dist
    If you don't have dist npm script in your package.json, call ./node_modules/.bin/electron-builder directly.
Or to avoid second step, append to first command /bin/bash -c "yarn && yarn dist" You can use /test.sh to install dependencies and run tests.
If you don't need to build Windows, use image electronuserland/builder (wine is not installed in this image).
NOTICE: Do not use Docker Toolbox on macOS. Only Docker for Mac works.

Provided Docker Images

  • builder:base — Required system dependencies. Not supposed to be used directly.
  • builder:9 or builder — NodeJS 9 and required system dependencies. Based on builder:base. Use this image if you need to build only Linux targets.
  • builder:wine — Wine, NodeJS 9 and required system dependencies. Based on builder:9. Use this image if you need to build Windows targets.
  • builder:wine-mono — Mono for Squirrel.Windows. Based on builder:wine. Use this image if you need to build Squirrel.Windows target.
  • builder:wine-chromegoogle-chrome-stable and xvfb are available — you can use this image for headless testing of Electron application. Based on builder:wine.
from  https://www.electron.build/multi-platform-build
--------

A complete solution to package and build a ready for distribution Electron app with “auto update” support out of the box

www.electron.build 

electron-builder npm version downloads per month donate

A complete solution to package and build a ready for distribution Electron, Proton Native app for macOS, Windows and Linux with “auto update” support out of the box. :shipit:

🔶 - Looking for additional maintainers!

We condemn Russia’s military aggression against Ukraine. We stand with the people of Ukraine.

Sponsors

WorkFlowy
Notes, Tasks, Projects.
All in a Single Place.


Tidepool
Your gateway to understanding your diabetes data


Keygen
An open, source-available software licensing and distribution API


ToDesktop
ToDesktop: An all-in-one platform for building and releasing Electron apps


Dashcam
Dashcam: Capture the steps to reproduce any bug with video crash reports for Electron.

Documentation

See the full documentation on electron.build.

  • NPM packages management:
  • Code Signing on a CI server or development machine.
  • Auto Update ready application packaging.
  • Numerous target formats:
    • All platforms: 7z, zip, tar.xz, tar.7z, tar.lz, tar.gz, tar.bz2, dir (unpacked directory).
    • macOS: dmg, pkg, mas.
    • Linux: AppImage, snap, debian package (deb), rpm, freebsd, pacman, p5p, apk.
    • Windows: nsis (Installer), nsis-web (Web installer), portable (portable app without installation), AppX (Windows Store), MSI, Squirrel.Windows.
  • Publishing artifacts to GitHub Releases, Amazon S3, DigitalOcean Spaces and Bintray.
  • Advanced building:
    • Pack in a distributable format already packaged app.
    • Separate build steps.
    • Build and publish in parallel, using hard links on CI server to reduce IO and disk space usage.
    • electron-compile support (compile for release-time on the fly on build).
  • Docker images to build Electron app for Linux or Windows on any platform.
  • Proton Native support.
  • Downloads all required tools files on demand automatically (e.g. to code sign windows application, to make AppX), no need to setup.
Question Answer
“I want to configure electron-builder” See options
“I found a bug or I have a question” Open an issue
“I want to support development” Donate

Installation

Yarn is strongly recommended instead of npm.

yarn add electron-builder --dev

Note for PNPM

In order to use with pnpm, you'll need to adjust your .npmrc to use any one the following approaches in order for your dependencies to be bundled correctly (ref: #6389):

node-linker=hoisted
public-hoist-pattern=*
shamefully-hoist=true

Note: Setting shamefully-hoist to true is the same as setting public-hoist-pattern to *.

Note for Yarn 3

Yarn 3 use PnP by default, but electron-builder still need node-modules(ref: yarnpkg/berry#4804). Add configuration in the .yarnrc.yaml as follows:

nodeLinker: "node-modules"

will declare to use node-modules instead of PnP.

Quick Setup Guide

electron-webpack-quick-start is a recommended way to create a new Electron application. See Boilerplates.

  1. Specify the standard fields in the application package.jsonname, description, version and author.

  2. Specify the build configuration in the package.json as follows:

    "build": {
      "appId": "your.id",
      "mac": {
        "category": "your.app.category.type"
      }
    }
  • See all options. Option files to indicate which files should be packed in the final application, including the entry file, maybe required. You can also use separate configuration files, such as js, ts, yml, and json/json5. See read-config-file for supported extensions. JS Example for programmatic API

  • Add icons.

  • Add the scripts key to the development package.json:

    "scripts": {
      "app:dir": "electron-builder --dir",
      "app:dist": "electron-builder"
    }
    1. Then you can run yarn app:dist (to package in a distributable format (e.g. dmg, windows installer, deb package)) or yarn app:dir (only generates the package directory without really packaging it. This is useful for testing purposes).

      To ensure your native dependencies are always matched electron version, simply add script "postinstall": "electron-builder install-app-deps" to your package.json.

    2. If you have native addons of your own that are part of the application (not as a dependency), set nodeGypRebuild to true.

    Please note that everything is packaged into an asar archive by default.

    For an app that will be shipped to production, you should sign your application. See Where to buy code signing certificates.

    from https://github.com/electron-userland/electron-builder 

    -----


    Electron Builder | 打包和构建可立即分发的 Electron 应用程序的完整解决方案

    A complete solution to package and build a ready for distribution Electron app for macOS, Windows and Linux with “auto update” support out of the box.

    推荐语:Electron Builder ,打包和 构建 可立即分发的 Electron 应用程序的完整解决方案,适用于 macOS、Windows 和 Linux,并提供开箱即用的“自动更新”支持,这对于基于 Electron、开发桌面应用程序的开发人员,能够提供积极的帮助;该项目在 Github 仓库开源:
    https://github.com/electron-userland/electron-builder

    https://www.electron.build

     

     
     

    No comments:

    Post a Comment