I'm developing an app which will be used by different companies. Each company should have their own app with different environment variables. Therefore, I got files named "env.js" similar to the following for each company:
window.companyName = 'abc';
window.apiUrl='http://localhost:8080/api/';
window.theme='abc';
At compile time, I'm setting an environment variable using set APP_BUILDENV=acb
.
Then, I'm hooking into ionics build:before and serve:before hooks to execute a script that copies the "env.js" file to the www directory. In index.html I include env.js as a script:
<script src="env.js"></script>
However, the devserver redirects the call to env.js to index.html so that the environment data is not loaded. How can I allow the browser to access the env.js?
I'm now exporting env.js to a directory named "config" and added the following to projects -> app -> architect -> build -> options in angular.json:
"scripts": [
{
"input": "config/env.js"
}
]