如何使用配置为ng e2e指定端口和主机 [英] How to specify the port and host for ng e2e using configuration

查看:62
本文介绍了如何使用配置为ng e2e指定端口和主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用配置文件为ng e2e命令设置端口和主机?

How do you set the port and host for the ng e2e command using a configuration file?

我知道可以在命令行中使用以下语句

I am aware that it is possible to use the following statement at the command line

ng e2e --port <port number> --host <host>

这很好用,但是在配置文件中设置端口和地址会更方便.我查看了.angular-cli.json的内部,发现有一个名为protractor.config.js的文件,我无法弄清楚该文件中要使用的设置,有一个baseUrl设置,但是更改该设置不会使与ng e2e命令使用的端口的差异.似乎正在使用随机端口.

This works nicely, but it would be more convenient to set the port and address in the configuration file. I have looked inside .angular-cli.json and found that there is a file called protractor.config.js, I've not been able to figure out what settings to use in that file, there's a baseUrl setting, but changing that does not make any difference to the port that is used by the ng e2e command. It seems to be using a random port.

除了baseUrl之外,我还尝试设置portseleniumPort,但是它们没有区别.

Aside from baseUrl I have also tried setting port and seleniumPort but they make no difference.

输入ng e2e命令后,以下输出将出现在控制台中

After entering the ng e2e command the following output appears in the in the console

** NG Live Development Server is running on http://localhost:49155 **

protractor.config.js中,我已将baseUrl设置为http://localhost:50000.我观察到正在执行的测试,并且可以看到浏览器正在使用地址http://localhost:49155,这不是我想要的地址.

In the protractor.config.js I have baseUrl set as http://localhost:50000. I have observed the tests executing and I can see that the browser is using the address http://localhost:49155 which is not the address that I desire.

ng --version返回后继

@ angular/cli:1.0.0
节点:7.7.1
操作系统:win32 x64
@ angular/common:4.0.3
@ angular/编译器:4.0.3
@角/芯:4.0.3
@ angular/forms:4.0.3
@ angular/http:4.0.3
@ angular/platform-b​​rowser:4.0.3
@ angular/platform-b​​rowser-dynamic:4.0.3
@角度/路由器:4.0.3
@ angular/cli:1.0.0
@ angular/compiler-cli:4.0.3

@angular/cli: 1.0.0
node: 7.7.1
os: win32 x64
@angular/common: 4.0.3
@angular/compiler: 4.0.3
@angular/core: 4.0.3
@angular/forms: 4.0.3
@angular/http: 4.0.3
@angular/platform-browser: 4.0.3
@angular/platform-browser-dynamic: 4.0.3
@angular/router: 4.0.3
@angular/cli: 1.0.0
@angular/compiler-cli: 4.0.3

推荐答案

运行ng e2e

您最好的选择可能是NPM脚本: https://docs.npmjs.com/misc/scripts

your best bet is probably an NPM script: https://docs.npmjs.com/misc/scripts

  1. "e2e":"ng e2e --port <port number> --host <host>"添加到scripts下的package.json
  2. 通过运行npm run e2e使用脚本,这将在package.json中运行脚本e2e,在本例中为ng e2e --port <port number> --host <host>
  1. Add "e2e":"ng e2e --port <port number> --host <host>" to package.json under scripts
  2. Use the script by running npm run e2e, this will run the script e2e in package.json, in this case your ng e2e --port <port number> --host <host>

它不是一个配置文件,但它的工作原理与一个文件相同.

It isnt a config file, but it works just like one.

这篇关于如何使用配置为ng e2e指定端口和主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆