I am curious if there is any more current practices here. A solution along the lines of what the OP is asking for is here: http://geekindulgence.com/environment-variables-in-angularjs-and-ionic/.
However, I don't like rewriting source. Not the end of the world but seems like too much machinery, IMO.
I also don't think detecting the platform is sufficient, since there might be (or in our case will be) a staging env as well as production.
My thoughts are to do something like this:
- Introduce a new file that "stamps" the current environment. Specifically I am thinking of a 1-line file that holds a global JS var like: env = 'development'; The Git repo would have the default development version.
- Add a build script that knows how to set up the environment, while hiding the implementation so that the process can stay consistent even if we change the impl. E.g. gulp build_env staging
- Include the stamp file in index.html
- Create angular constants for environment-based properties, set up conditionally based on the value of the env variable. Note if dynamic loading of JS like Require.js is in place, then one can conditionally require a different version of the constants source file.