使npm启动脚本在特定端口运行服务

BBa*_*ger 3 node.js npm angular

我有一些脚本package.json,我需要知道如何让start脚本正确接受-portangular-cli 的参数.

  "scripts": {
    "ng": "ng",
    "start": "ng serve  --proxy-config proxy.conf.json",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
Run Code Online (Sandbox Code Playgroud)

我们需要这个,因为我们想同时运行我们软件的多个实例.目前,如果我有一个项目在默认端口4200上运行,并尝试npm start -port 4300在第二个终端窗口中运行,我得到,"端口4200已经在使用中.使用'--port'指定不同的端口."

我该怎么做才能让我的构建在特定端口运行?我怎么能这样做,以便我可以从命令行将端口号传递到npm启动脚本?

小智 13

如果添加" - ",则参数将通过:

npm start -- --port 4301
Run Code Online (Sandbox Code Playgroud)


Saj*_*ran 5

把它改成,

"scripts": {
    "ng": "ng",
    "start": "ng serve --port 4301",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
Run Code Online (Sandbox Code Playgroud)