Angular10如何修改默认端口号
1.网上很多帖子说让你去找
node_modules/@angular/cli/lib/config/schema.json
这个文件里面有
"port": {
"type": "number",
"description": "Port to listen on.",
"default": 4200
},
但你改这个就好使了吗?结果
PS C:\Users\XXX\new Tarniing\test9527> npm start
> test9527@0.0.0 start C:\Users\XXX\new Tarniing\test9527
> ng serve
An unhandled exception occurred: Port 4200 is already in use. Use '--port' to specify a different port.
See "C:\Users\SHIBO~1.ZHO\AppData\Local\Temp\ng-NAPeto\angular-errors.log" for further details.
其实并没有用,最简单有效的办法就是直接
PS C:\Users\XXX\new Tarniing\test9527> ng serve --port 4201
(注意--port之间没有空格 有空格不行)
如果你想直接 npm start 启动的话就需要写一个东西,在package.json 下的修改我打**的那句话
"scripts": {
"ng": "ng",
**"start": "ng serve --port 4201",**
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
就成功了。