I have different env settings for each customer with each having it's own {{custName}}/environment.prod.ts file . I want to use their respective prod environment files with ng build --prod command. The problem I'm facing is even after specifiying the environment it's using the default environment.prod.ts
My package.json has script like
{.....
customer_a : "ng build --prod --environment=custA_prod",
....}
In angular-cli.json I have mentioned the path which goes something like this
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts",
"qa": "environments/environment.qa.ts",
"custA_prod": "environments/custA/environment.prod.ts"
}
Is it possible to use all the features of prod build but with some different environment settings ?
Adding multiple environments: Open your angular project in a preferred IDE. Navigate to src>environments, there you can see two files environment. ts and environment.
Both files are configuration files (global variables ) with different values. When you build or run your project in development environment “environment. ts” file will be used. Whereas if you run your project in production mode “environment.
After Angular 6+, angular.cli.json has been replaced by angular.json. We should use --configuration as bellow
package.json
"build_dev": "npm run && ng build --configuration=test",
angular.json
...
"configurations": {
.....
"test": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.test.ts"
}
]
}
}
mark as production mode on you enviorement file:
environments/custA/environment.prod.ts File:
export const environment = {
production: true,
envName: "custA_prod",
.....
};
Or add main.ts your custom check:
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
if (environment.production || environment.envName == 'custA_prod') {
enableProdMode();
}
platformBrowserDynamic().bootstrapModule(AppModule);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With