Search code examples
electronelectron-builderelectron-packagerelectron-forge

Build electron as exe on macbook m1


I trying to build an electron with an exe installer on macOS with a MacBook Pro with an m1. I already tried different packages like electron-packager, electron-forge, but unfortunately, none of my tries worked. Did anyone has a solution to build an electron version with an exe on macOS. My latest approach looked like, but when I start and after more then 30 minute it still do no finish.

yarn run electron-forge make --arch=x64 --platform=win32

The current code could be found here.


Solution

  • We using electron-builder for packaging electron app on Windows&MacOS(x86_x64/arm etc.), and you can try it.

    add some config in package.json, like this:

    
      "build": {
        "appId": "com.electron.yourappid",
        "productName": "your-product-name",
        "asar": false, 
        "mac": {
          "target": [
            "pkg"
          ],
          "entitlements": "entitlements.mac.plist"
        },
        "win": {
          "target": [
            {
              "target": "zip",
              "arch": [
                "x64"
              ]
            },
            {
              "target": "msi",
              "arch": [
                "x64"
              ]
            }
          ]
        }
      },
      "scripts": {
        "dist": "electron-builder"
      },
    

    then run npm command like this:

    # add package in your project
    npm install --save-dev electron-builder
    npm run dist # or 'npx electron-builder'
    

    If you perfer using 'shelljs', create a file 'dist.js', and content:

    const { exec, rm } = require('shelljs');
    exec('electron-builder');
    

    and then run node command

    npm install --save-dev shelljs
    node dist.js
    

    More detail for config you can read offical doc of electron-builder.