-
Notifications
You must be signed in to change notification settings - Fork 12k
Add environment config to builds #411
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
Add environment config to builds #411
Conversation
This LGTM, let's see what comes out of the discussion in styleguide. |
So after working with Igor and Filipe during the meeting, here's the path forward:
declare var __ENV__ : { [name: string]: any };
export default __ENV__;
import environment from 'environment';
// ...
if (environment.production) { enableProdMode(); }
|
What do you think? |
I like the simpler I guess it caters to the server-side rendering scenario by moving the logic elsewhere, so the bootstrap doesn't have to be more complex. Now that I think of it, on apps with a lot of nested routes I'd much prefer to have a provider I can use than to do What's the usecase for having a default template? Is this something you've felt the need for? I haven't yet, but that doesn't mean it's not useful. I'm not too keen on putting stuff on In this scenario, we create End result would be the same, without having to fiddle with |
So in Django you get a default set of options for the environment, which is overwritten by the environment that you need. So something like this exists: // environment.default.ts
export default = {
production: false,
backendUrl: 'http://localhost:9999/',
firebaseUrl: 'http://blah/',
}; // environment.dev.ts
import DEFAULTS from './environment.default'
export default = Object.assign(DEFAULTS, {
}); // environment.e2e.ts
import DEFAULTS from './environment.default'
export default = Object.assign(DEFAULTS, {
production: true,
// Use same backends as DEV
}); // environment.prod.ts
import DEFAULTS from './environment.default'
export default = Object.assign(DEFAULTS, {
production: true,
backendUrl: 'http://blah',
firebaseUrl: 'http://bleh/',
}); I guess the default could always be DEV, but it's better to dissociate DEV from anything else since it might lead to mistakes and expose data you don't want to. |
Thinking a bit more about That way the provider can be a straight up import of |
Ok the defaults make more sense now. These env files seem the perfect place to add the firebase info, and even APP_BASE_HREF (github deploys need a specific one, for instance). |
a494333
to
0e5117d
Compare
Removed provider, but didn't incorporate the defaults because it made the process more complicated when using more environments that don't extend dev ( |
We already have a |
I thought about it at the start, but then assumed it would be problematic because of the whole But with you mentioning it now I agree it's much better to have those files out of the client and in config. |
0e5117d
to
23b5d5e
Compare
import {<%= jsComponentName %>App} from './app/<%= htmlComponentName %>'; | ||
|
||
bootstrap(<%= jsComponentName %>App, []); | ||
if (environment.production) { enableProdMode(); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Split the lines, this might trigger the linter :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Roger.
Can you add the overwriting of the environment by the build system in this PR? Then I think this will be ready to go. |
23b5d5e
to
c7b333a
Compare
c7b333a
to
8e4885c
Compare
@hansl done, please review. |
b7c5c90
to
d6db64f
Compare
@hansl tests are fixed. |
LGTM. We should add support for multiple builds in the future, but for now this is 👍. |
@hansl agree, atm just wanted to get something in this week. |
d6db64f
to
372354f
Compare
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. |
See #41 (comment)
Environments
At build time, the
src/client/app/environment.ts
will be replaced by eitherconfig/environment.dev.ts
orconfig/environment.prod.ts
, depending on thecurrent cli environment.
Environment defaults to
dev
, but you can generate a production build viathe
-prod
flag in eitherng build -prod
orng serve -prod
.