Ionic build system custom flag

How can I add a custom flag for an Ionic build?

My app uses GPS geolocations and for testing I would like to randomize the locations from a preset list so that I catch behavior around the world. For now I have a combination of bash & sed scripts that automatically edits my source file if I set a flag before I run my build script wrapper . However, I would like this to be more elegant and somehow part of the ionic & capacitor build system.
I would like to run the ionic build with --random and thus it would create a switch in the source to randomize a value.


Is there a reason this can’t be done by a custom entry in the scripts section of package.json? That’s where I run similar things that (for example) bake version control slugs into the source.

Is there a how to for this? I’m not sure how this would be specifically called to search for it properly.

I’m thinking in a C perspective here. I would like to set some precompiled flags that would set values in the code prior to build / compilation. Is this possible?

Well, there’s the npm docs on the topic.