bennymeg / nx-electron

Electron schematics for nrwl nx platform
Apache License 2.0
316 stars 84 forks source link

[Question] How to create multi platform builds? #129

Closed julianpoemp closed 2 years ago

julianpoemp commented 2 years ago

I don't understand how to build the electron app to binaries for multi platforms. I'm using MacOS 11.6.2 and I would like to build a binary for windows and linux, too.

How can I do this using nx-electron and Angular?

naej56 commented 2 years ago

Hi @julianpoemp,

I think you meen packing your application.

You have two choices for that :

1) use option --plateform in your packing command.

Exemple for windows and linux packing : nx run <electron-app-name>:package --plateform=windows,linux You can find all option on this page

2) use static packing configuration.

You can find exemple on this page You can find all options and détails on Electron Builder documentation Notice : Static configuration will overide the options you pass manually via the command line or choose via the angular console.

Hope this can help you.

julianpoemp commented 2 years ago

Hi @naej56,

thank you for your fast answer 😄

I tried it using --platform but it doesn't work. It still builds only the MacOS version.

I tried two different ways to pass the platformargument:

  1. In the build command:

    nx run :package --platform=windows

  2. After that hadn't worked I tried to append it in the angular.json file:

       ...
        "package": {
          "builder": "nx-electron:package",
          "options": {
            "platform": "windows",
            "name": "<electron-app>",
            "frontendProject": "<electron-app>",
            "outputPath": "dist/packages",
            "prepackageOnly": true
          }
        },
        ...

Both didn't work...

naej56 commented 2 years ago

i have no way to test right now sorry.

But may be you could try with a config file .\apps\<electron-app-name>\src\app\options\maker.options.json

julianpoemp commented 2 years ago

@naej56 no problem. I'm currently testing a possible solution. If it works, I'll write it here.

bennymeg commented 2 years ago

@julianpoemp multiplatform builds are not a trivial thing, especially on mac.

You will need to compile the program with the target machine instructions set. Which means you will probably need to invoke the packager inside a docker container/virtual machine/build server that runs your target platform.

You can find detailed explanation on this document.

julianpoemp commented 2 years ago

I got it working with nx-electron. I had to install a 64bit version of wine on MacOS BigSur. Because --platform falls to default while using prepackageOnly=true I set it to false for all platforms. I don't understand why this happens, but it works. Further more I had to set the base-href attribute to "./". Further more I had to set the "arch" and "target" attributes to the windows options in the maker.options.jsonfile. I can now build binaries for macOS, Windows and Linux on the same computer.

The command I'm using is:

nx build <frontend-app> --prod --base-href='./' && nx build <electron-app> --prod && nx run <electron-app>:package --platform=windows --prepackageOnly=false

Thank you for your help! 😃

bennymeg commented 2 years ago

I didn't knew Wine is an option one can use, nice. You should use the following command instead:

nx build <frontend-app> --prod --base-href='./' && nx build <electron-app> --prod && nx run <electron-app>:make --platform=windows
tmtron commented 2 years ago

nx build --prod --base-href='./' && nx build --prod && nx run :make --platform=windows

@bennymeg where does the platform parameter come from?

bennymeg commented 2 years ago

All the executors have a schematic file (which is where the platform option comes from). The package executor have an additional schematic for the builder options.

I do not use the CLI, I use the API (which is poorly documented), you can find more information about the platform variable inside electron-builder source files. (Platform, createTargets).

tmtron commented 2 years ago

Okay, then I think it's like this:

The validation/maker.schema.json is used to validate the maker.options.json file

bennymeg commented 2 years ago

Correct

etiennea commented 3 months ago

This was not clear, could be made clearer in docs