angular-cli change port to 3000 in angular-cli.jso

2019-02-21 08:37发布

i use the material todo app from Daniel Zen and want to change to port in the angular-cli.json. https://github.com/danielzen/material-todo

But this doesn't work. I tried this:

{
  "port" : 3000,

But nothing happens. Anyone an idea?

2条回答
仙女界的扛把子
2楼-- · 2019-02-21 08:58

Edit with Angular-CLI 1.0.0

You can now directly define the used port in the .angular-cli.json file by defining the property like this:

{
    "defaults": {
        "serve": {
            "port": 2500
        }
    }
}

Here is a direct link to all available options for the configuration: Angular-CLI options configuration

Old Answer

You can configure it directly in your packages.json, change your start scripts by:

"start": "ng serve --port 2500",

And then run your server with npm start

查看更多
3楼-- · 2019-02-21 09:05

As in new version .angular-cli.json is not visible. You can set port in serve section of angular.json like this:

"serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "formation:build",
            "port": 5001
          },
 ....

You can add any port number instead of 5001

Thats how you can set your host aswell, just like port:

"host": "your_host_name"
查看更多
登录 后发表回答