-
Notifications
You must be signed in to change notification settings - Fork 12k
Cannot change environment at runtime #2508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I was running into an issue yesterday for this reason. I wanted to change href of base tag in index.html to host Angular app in su folder when deployed to any other environments than local. But, I had to explore changes in deployment process instead of having this ability as part of Angular build. |
+1 This is a major shortcoming. We should not be embedding the environment configuration with the deployed app. The configuration should be externalizable. The internal environment object should function as little more than a stub to allow easy referencing of the set of possible config properties, but the values should be defined outside. |
Pragmatically, I am in need of this functionality as well, to configure which backend services to contact. |
I agree that changing environment at runtime is an important feature - but that doesn't mean that build-time environment is not important. Different projects need to do different things with their environment config. At the very least, it needs to switch over Angular itself from dev to prod mode. A lot of users also need to load some extra modules. Static env files serve that purpose well. Mind you that just because the CLI doesn't have a recommendation for this functionality it doesn't mean you can't just do it yourself. If your app truly is able to be configured at runtime, the built artefact should stay the same, thus no build-time support is needed for it. |
For those who need an easily modifiable "App config" object, this is how I ended up doing it:
and make it available with a provider like this
...with The slightly roundabout notation with an So I don't consider it particularly high priority for the CLI, but I'd still like to see clever heads get together and figure out the smoothest, most elegant way to do it, in particular if it has to work with Universal or other situations without a window object to carry the globals. |
Closing in favor of #3855, there is further discussion there. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
We would like to be able to change the environment at runtime. Currently, this is not possible, as the
environment.ts
file gets compiled into themain.bundle.js
with the rest of the code. Instead, the dist should have a separateenvironment.js
file, so that it can be replaced at runtime.Setting the environment at runtime is a very important feature for release pipelines. It does not make sense to build an artifact to test on a lower environment, and then have to build a new artifact for production. Being able to pass an artifact off to the higher environment provides assurance that you are releasing the same thing that you tested.
Versions.
angular-cli: 1.0.0-beta.15
node: 6.6.0
os: darwin x64
Repro steps.
ng build
Notice that the
dist
directory does not have a file dedicated to environment config.The text was updated successfully, but these errors were encountered: