8

This is the first time I am building electronjs app so most probably I don't know what I am doing.

I follow the instruction from the github and this. This is my package.json:

{
  "name": "ExampleApp",
  "productName": "ExampleApp",
  "version": "1.0.0",
  "description": "Fun app.",
  "license": "MIT",
  "repository": "user/repo",
  "author": {
    "name": "sooon",
    "email": "Example@gmail.com",
    "url": "Example.com"
  },
  "build": {
    "appId": "com. Example.ExampleApp",
    "mac": {
      "target": "dmg",
      "icon": "build/icon.png"
    },
    "win": {
      "target": "nsis",
      "icon": "build/icon.png"
    }
 },
  "scripts": {
    "test": "xo",
    "start": "electron .",
    "pack": "electron-builder --dir",
    "dist": "electron-builder"
  },
  "dependencies": {
    "electron-debug": "^1.0.0",
    "jquery": "^3.3.1"
  },
  "devDependencies": {
    "devtron": "^1.1.0",
    "electron": "^1.8.2",
    "electron-builder": "^19.56.0",
    "electron-packager": "^8.7.2",
    "xo": "^0.18.0"
  },
  "xo": {
    "envs": [
      "node",
      "browser"
    ]
  }
}

As you can see I have mac and win in the build script. But when I run:

nom run dist

only DMG file (fully functional) is build. There is not trace of any work with win app. What had I miss out in the setting?

I am building this with my MacBook running on 10.12.6. Is it only you can build for your own platform? Can Mac build for Windows?

Update01 I took out:

"build": {
    "appId": "com.sooonism.pipidance",
    "mac": {
      "target": "dmg",
      "icon": "build/icon.png"
    },
    "win": {
      "target": "nsis",
      "icon": "build/icon.png"
    }
 },

from the package.json and it still build ok. That means the build script is located somewhere maybe?

sooon
  • 4,718
  • 8
  • 63
  • 116
  • Did you ever find a solution to this? I'm having the same problem - it seems to just do the default regardless of whether the `build` key is defined in package.json or not. – Nic Barker Sep 05 '18 at 03:18
  • This `package.json` works for both. But you need the OS to build them. to build for mac, you need run `build` in `macos`, and vice versa for `win`. – sooon Sep 05 '18 at 04:29

1 Answers1

19

electron-builder defaults to building for the current platform. To build both, you need to do something like this in the "script", to build the mac and the window:

"dist-all": "electron-builder -mw"

Jane Ku
  • 206
  • 3
  • 3
  • 2
    Thanks, this fixed the problem for me. I don't know why it isn't mentioned in the docs anywhere. – Nic Barker Sep 05 '18 at 03:22
  • 1
    I haven't tried this though. what platform did you use to build? – sooon Sep 05 '18 at 04:31
  • 1
    @sooon I was able to build both mac .dmg and windows nsis apps on mac os x using `electron-builder -mw` – Nic Barker Sep 05 '18 at 05:51
  • I had the exact same problem. Flushed 2 hours down the toilet on this. This seems like something worth mentioning prominently in the documentation. – Kywillis Dec 20 '20 at 23:47