9.21.2017

Angular Development Production Settings

This came from this post

Angular apps created using angular-cli will have src/environments directory.

1. Add another file in there called environment.staging.ts with the following entry...
export const environment = {
  production: false,
  envName: 'staging'
};

2. Modify .angular.cli.json
"environments": {
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts",
        "staging": "environments/environment.staging.ts"
      }

3. Now when creating a build or serving the app..
$ ng build -prod
$ ng build -staging
$ ng serve -prod
$ ng serve -staging

4. To use...
import { environment } from './environment';
export class MyappAppComponent {  
  title = 'myapp works!';
  environmentName = environment.envName;
}

No comments:

Post a Comment