angular-cli server - how to specify default port

前端 未结 8 1018
星月不相逢
星月不相逢 2020-12-04 10:42

Using angular-cli with the ng serve command, how can I specify a default port so I do not need to manually pass the --port flag every time?

8条回答
  •  星月不相逢
    2020-12-04 11:19

    In Angular 2 cli@2.3.1,

    To run a new project on the different port, one way is to specify the port while you run ng serve command.

    ng serve --port 4201
    

    or the other way, you can edit your package.json file scripts part and attached the port to your start variable like I mentioned below and then simply run "npm start"

     "scripts": {
    
        "ng": "ng",
        "start": "ng serve --port 4201",
        ... : ...,
        ... : ....
    }
    

    this way is much better where you don't need to define port explicitly every time.

提交回复
热议问题