Set default host and port for ng serve in config file

后端 未结 12 2232
庸人自扰
庸人自扰 2020-12-07 07:53

I want to know if i can set a host and a port in a config file so I don\'t have to type

ng serve --host foo.bar --port 80

instead of just

12条回答
  •  不知归路
    2020-12-07 08:48

    Angular CLI 6+

    In the latest version of Angular, this is set in the angular.json config file. Example:

    {
        "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
        "projects": {
            "my-project": {
                "architect": {
                    "serve": {
                        "options": {
                            "port": 4444
                        }
                    }
                }
            }
        }
    }
    

    You can also use ng config to view/edit values:

    ng config projects["my-project"].architect["serve"].options {port:4444}
    

    Angular CLI <6

    In previous versions, this was set in angular-cli.json underneath the defaults element:

    {
      "defaults": {
        "serve": {
          "port": 4444,
          "host": "10.1.2.3"
        }
      }
    }
    

提交回复
热议问题