Search code examples
electronelectron-forge

Setting platform dependant icon via electron-forge electronPackagerConfig


Using electron-forge to build a desktop app. The app is built for both OSX & Windows. Inside my package.json, I have:

"electronPackagerConfig": {
    "icon": "src/images/icon/app_icon_osx.icns"
}

When I build on Windows, I'm having to manually change the icon in package.json from "app_icon_osx.icns" to "app_icon_win.ico".

If I try to just use "app_icon.png" for both platforms, the icon doesn't show on OSX, and the build fails with "rcedit.exe failed with exit code 1. Fatal error: Unable to set icon" on Windows.

I have all 3 versions of the icon (icns, ico, png) in a folder in the project. Because i'm using electron-forge, i don't seem to be able to use electron packager's --icon argument.

Is there a way I can pass the icon to use as a command line arg, instead of hardcoded in package.json? Or a way I can use the same png for both platforms?


Solution

  • The extension is automatically added for each platform. Just supply an icon per platform like this: app_icon.icns, app_icon.ico, ...

    Then update your config:

    "electronPackagerConfig": {
        "icon": "src/images/icon/app_icon"
    }