如何为不同版本的Angular 2 | 4 | 5 | 6创建项目

时间:2018-07-31 07:20:09

标签: angular angular-cli angular6 angular2-cli

在我的window 8系统中,已安装Angular CLI 6.1.1。我想为Angular2,Angular4,Angular5和Angular6创建项目。但是,当我使用以下命令创建项目时:

  

ng新演示

在pachage.json中添加以下代码:

    {
  "name": "demo2",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^6.1.0",
    "@angular/common": "^6.1.0",
    "@angular/compiler": "^6.1.0",
    "@angular/core": "^6.1.0",
    "@angular/forms": "^6.1.0",
    "@angular/http": "^6.1.0",
    "@angular/platform-browser": "^6.1.0",
    "@angular/platform-browser-dynamic": "^6.1.0",
    "@angular/router": "^6.1.0",
    "core-js": "^2.5.4",
    "rxjs": "^6.0.0",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.7.0",
    "@angular/cli": "~6.1.1",
    "@angular/compiler-cli": "^6.1.0",
    "@angular/language-service": "^6.1.0",
    "@types/jasmine": "~2.8.6",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.2.1",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~1.7.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.0",
    "karma-jasmine": "~1.1.1",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.3.0",
    "ts-node": "~5.0.1",
    "tslint": "~5.9.1",
    "typescript": "~2.7.2"
  }
}

如何为Angular 2 | 4 | 5 | 6创建项目?

2 个答案:

答案 0 :(得分:0)

在Package.json中,我们只能配置2/4/5/6的一个Angular版本。据我所知,Angular CLI在单个代码库中不支持多个Angular项目。

答案 1 :(得分:0)

您可以使用npx临时下载特定版本的ng cli并使用它来创建脚手架,例如npx -p @angular/cli ng new hello-world-project