How to config different development environment in Angular 2 app

后端 未结 5 751
遇见更好的自我
遇见更好的自我 2020-12-08 04:37

I have a constant file

export class constants {
    public static get API_ENDPOINT(): string { return \'https://dvelopment-server/\'; }
}

5条回答
  •  暖寄归人
    2020-12-08 05:06

    Short answer: use Angular CLI. It is in beta stage but works really well and it's recommended by the Angular Team for starting new projects. With this tool you can configure different environments. At build time, the src/client/app/environment.ts will be replaced by either config/environment.dev.ts or config/environment.prod.ts, depending on the current CLI environment.

    Environment defaults to dev, but you can generate a production build via the -prod flag in either ng build -prod or ng serve -prod. Given that this is a new feature, it can be a bit confuse, so look at this great guide for additional info about how to set up Angular Environments using CLI.

    Hope this helps.

提交回复
热议问题