How to config different development environment in Angular 2 app

后端 未结 5 749
遇见更好的自我
遇见更好的自我 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:03

    I hope it helps.

    First, create development.ts, staging.ts, production.ts configuration files. Second, in your index.pug, import the environment file in the following way:

       SystemJS.import("#{settings.env}").then(function(env) {
           System.import("app").catch(console.error.bind(console));
       } // Promise.all also works!
    

    Remember that in nodeJS/Pug/Jade settings.env contains the NODE_ENV value.

    And finally, your system.config.ts map should have the following lines:

        "development": "myUrl/configs/development.js",
        "staging": "myUrl/configs/staging.js",
        "production": "myUrl/configs/production.js",
    

提交回复
热议问题