angular-cli服务器 – 如何指定默认端口
在ng serve
命令中使用angular-cli,我怎样才能指定一个默认的端口,所以我不需要每次都手动传递--port
标志?
更新@ angular / cli final:在angular-cli.json
里面你可以指定默认的端口:
"defaults": { "serve": { "port": 1337 } }
遗产:
在angular-cli@1.0.0-beta.22-1中testing
angular-cli
的服务器来自于ember-cli
项目。 要configuration服务器,请在项目根目录下创build一个.ember-cli
文件。 在这里添加你的JSONconfiguration:
{ "port": 1337 }
重新启动服务器,它将服务于该端口。
这里指定了更多选项: http : //ember-cli.com/#runtime-configuration
{ "skipGit" : true, "port" : 999, "host" : "0.1.0.1", "liveReload" : true, "environment" : "mock-development", "checkForUpdates" : false }
在Angular 2 cli@2.3.1中,
要在不同的端口上运行新项目,一种方法是在运行ng serve命令时指定端口。
ng serve --port 4201
或者其他的方式,你可以编辑你的package.json文件脚本部分,并将端口添加到你的启动variables,就像我之前提到的,然后运行“npm start”
"scripts": { "ng": "ng", "start": "ng serve --port 4201", ... : ..., ... : .... }
这种方式更好,你不需要每次明确定义端口。
使用npm脚本来代替…编辑你的package.json并将命令添加到脚本部分。
{ "name": "my new project", "version": "0.0.0", "license": "MIT", "angular-cli": {}, "scripts": { "ng": "ng", "start": "ng serve --host 0.0.0.0 --port 8080", "lint": "tslint \"src/**/*.ts\" --project src/tsconfig.json --type-check && tslint \"e2e/**/*.ts\" --project e2e/tsconfig.json --type-check", "test": "ng test", "pree2e": "webdriver-manager update --standalone false --gecko false", "e2e": "protractor" }, "private": true, "dependencies": { "@angular/common": "^2.3.1", "@angular/compiler": "^2.3.1", "@angular/core": "^2.3.1", "@angular/forms": "^2.3.1", "@angular/http": "^2.3.1", "@angular/platform-browser": "^2.3.1", "@angular/platform-browser-dynamic": "^2.3.1", "@angular/router": "^3.3.1", "core-js": "^2.4.1", "rxjs": "^5.0.1", "ts-helpers": "^1.1.1", "zone.js": "^0.7.2" }, "devDependencies": { "@angular/compiler-cli": "^2.3.1", "@types/jasmine": "2.5.38", "@types/node": "^6.0.42", "angular-cli": "1.0.0-beta.26", "codelyzer": "~2.0.0-beta.1", "jasmine-core": "2.5.2", "jasmine-spec-reporter": "2.5.0", "karma": "1.2.0", "karma-chrome-launcher": "^2.0.0", "karma-cli": "^1.0.1", "karma-jasmine": "^1.0.2", "karma-remap-istanbul": "^0.2.1", "protractor": "~4.0.13", "ts-node": "1.2.1", "tslint": "^4.3.0", "typescript": "~2.0.3" } }
然后执行npm start
您现在可以在.angular-cli.json中的默认值下指定端口:
"defaults": { "styleExt": "scss", "serve": { "port": 8080 }, "component": {} }
在angular-cli v1.0.6中testing