Ionic prod release build incorrectly adding development provision profile

We are trying to build a production release of our application using the standard Ionic CLI (v3.5.0) command:

ionic cordova build ios --device -- --prod --release

However, when we add the app to our test device device through Apple Configurator 2 it fails to install the app, showing errors in the logs due to an invalid provisioning profile. Inspecting the generated IPA file to check the embedded.mobileprovision file, we see there are key entries for the developer provisioning profile and also ProvisionedDevices, with our device ID, rather than the key for ProvisionsAllDevices instead.

So, we tried specifying the team and profile to the build command, e.g.

ionic cordova build ios --device --prod --release -- --codeSignIdentity="iPhone Distribution: MY COMPANY" --provisioningProfile="UUID-blah"

Throughout the build debug output is showed that it was using the signing identity and provisioning profile provided:

    Signing Identity:     "iPhone Distribution: MY COMPANY"
    Provisioning Profile: "2017 My App (In-House Distribution)"
    (UUID-blah)

Again after inspecting the generated IPA, the embedded.mobileprovision file has a key entry for the developer provisioning profile, i.e. 2017 My App (Dev) and ProvisionedDevices, along with a device ID, rather than the distributions provisioning profile and the key for ProvisionsAllDevices.

So, firstly, why is it doing this?

Also, when we then removed the development provisioning profile from the Apple developer account / dev machine file cache and re-ran the last command with the codeSigningIdentiy it failed to build, with the error:

error: exportArchive: No valid iOS Development signing identities belonging to team {MY_TEAM_ID} were found.

Why is it trying to use the development signing identity when exporting a production release with a specified team and signing identity?

We would really appreciate any help on this as it is causing a huge problem releasing the application.

It’s been a year for this post and we don’t have any answer from Ionic team.
Thank you guys!!