Set default host and port for ng serve in config file

后端 未结 12 2157
庸人自扰
庸人自扰 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:40

    If your are on windows you can do it this way :

    1. In your project root directory, Create file run.bat
    2. Add your command with your choice of configurations in this file. For Example

    ng serve --host 192.168.1.2 --open

    1. Now you can click and open this file whenever you want to serve.

    This not standard way but comfortable to use (which I feel).

    0 讨论(0)
  • 2020-12-07 08:41

    You can configure the default HTTP port and the one used by the LiveReload server with two command-line options :

    ng serve --host 0.0.0.0 --port 4201 --live-reload-port 49153

    https://github.com/angular/angular-cli

    0 讨论(0)
  • 2020-12-07 08:42

    If you are planning to run the angular project in custom host/IP and Port there is no need of making changes in config file

    The following command worked for me

    ng serve --host aaa.bbb.ccc.ffffd --port xxxx
    

    Where,

    aaa.bbb.ccc.ffffd --> IP you want to run the project
    xxx --> Port you want to run the project
    

    Example

    ng serve --host 192.168.322.144 --port 6300
    

    Result for me was

    0 讨论(0)
  • 2020-12-07 08:47

    You can save these in a file, but you have to to put it in .ember-cli (at the moment, at least); see https://github.com/angular/angular-cli/issues/1156#issuecomment-227412924

    {
    "port": 4201,
    "liveReload": true,
    "host": "dev.domain.org",
    "live-reload-port": 49153
    }
    

    edit: you can now set these in angular-cli.json as of commit https://github.com/angular/angular-cli/commit/da255b0808dcbe2f9da62086baec98dacc4b7ec9, which is in build 1.0.0-beta.30

    0 讨论(0)
  • 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"
        }
      }
    }
    
    0 讨论(0)
  • 2020-12-07 08:48

    enter image description here

    Only one thing you have to do. Type this in in your Command Prompt: ng serve --port 4021 [or any other port you want to assign eg: 5050, 5051 etc ]. No need to do changes in files.

    0 讨论(0)
提交回复
热议问题