Support Additional Environments
angular-cli: 1.0.0-beta.5
node: 5.10.0
os: darwin x64
Reproduction Steps
- Update
config/environment.prod.tswith the following contents:
export const environment = {
production: true,
service_root: 'http://prod.example.com'
};
- Create a file
config/environment.preprod.tswith the following contents:
export const environment = {
production: true,
service_root: 'http://preprod.example.com'
};
- Build the project using the command
ng build -e preprod - Check out the contents of
dist/index.js
The value of "service_root" should be set to 'http://preprod.example.com' but instead it pulled in the value from the production environment. If you change the production value of the preprod file to false it will instead use the value from the dev environment.
It appears that the changes to /lib/broccoli/environment.js only end up producing a true|false value for whether or not it is production. The actual configuration file that is used will still only be either environment.prod.ts or environment.dev.ts.
The reason is due to this code here: https://github.com/angular/angular-cli/blob/master/lib/broccoli/angular2-app.js#L397
var envConfigFile = isProduction ? 'environment.prod.ts' : 'environment.dev.ts';
It should instead be using the same logic present in https://github.com/angular/angular-cli/blob/master/lib/broccoli/environment.js. There is a little magic around the special keywords of production and development turning into prod and dev respectively, but it should instead be something like this:
var envConfigFile = `config/environment.${env}.ts`;
I'm actually getting ready to work an this feature, using SystemJS conditional mappings.
Great news. Thanks!
It would also be nice if we could control bundling/minification via the environment configs? so for example instead of:
if (loadEnvironment(this.project).production) {
merged = this._getBundleTree(merged);
}
we could use
if (loadEnvironment(this.project).build.bundle) {
merged = this._getBundleTree(merged);
}
So maybe there is an build: {} object in the environment.*.ts where we could set these kind of things. Is there an issue or an design doc for the build? i couldn't find anything.
@dominikstrasser that touches on a somewhat more sensitive subject, the decoupling of build options and environment options.
For instance, I might want a production build (bundling and whatnot) using my dev environment app configuration. Vise versa is also a possible scenario.
Still have to think a bit more about it and how to do it.
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.