“获取未知”选项:运行yarn build:prod Angular 6时使用“ -p”

Akh*_*rma 2 javascript yarnpkg angular angular6

我从最近两天开始面临这个问题。我已经将Angular的版本从版本4更新到了版本6,但是之后,我无法创建生产版本。纱线构建,纱线开发等命令运行正常。但是,当我运行yarn build:prod时,出现错误未知选项:-p。我对Angular来说还很陌生,无法弄清楚出了什么问题。因此,任何帮助将不胜感激。

Package.json

    {
  "name": "nitrogen",
  "version": "0.0.1",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "dev": "node --max_old_space_size=8000 ./node_modules/.bin/ng serve --proxy-config proxy.conf.json",
    "serve:prod": "yarn build:prod && hs -p 4200 dist/",
    "build": "ng build",
    "build:dev": "ng build --statsJson",
    "build:prod": "ng build -prod -aot --statsJson -d /admin",
    "test": "ng test",
    "coverage": "ng test --watch false --cc",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^5.0.0",
    "@angular/common": "^5.0.0",
    "@angular/compiler": "^5.0.0",
    "@angular/core": "^5.0.0",
    "@angular/forms": "^5.0.0",
    "@angular/http": "^5.0.0",
    "@angular/platform-browser": "^5.0.0",
    "@angular/platform-browser-dynamic": "^5.0.0",
    "@angular/router": "^5.0.0",
    "@types/underscore": "^1.8.8",
    "angular2-text-mask": "^8.0.5",
    "bootstrap": "^3.3.7",
    "core-js": "^2.5.7",
    "file-saver": "^1.3.8",
    "jquery": "^3.3.1",
    "moment": "^2.22.2",
    "ng2-file-upload": "^1.3.0",
    "ng2-nvd3": "^2.0.0",
    "ngx-bootstrap": "^1.9.3",
    "ngx-cookie": "^1.0.0",
    "ngx-toastr": "^6.3.0",
    "node-sass": "^4.9.0",
    "raven-js": "^3.26.2",
    "rxjs": "^5.5.11",
    "underscore": "^1.9.1",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.6.8",
    "@angular/cli": "^6.0.8",
    "@angular/compiler-cli": "^5.0.0",
    "@angular/language-service": "^5.0.0",
    "@types/file-saver": "^1.3.0",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "^6.0.112",
    "codelyzer": "~3.2.0",
    "http-server": "^0.10.0",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.4.3",
    "karma-jasmine": "^1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~3.2.0",
    "tslint": "~5.7.0",
    "typescript": "~2.4.0"
  `}
`}
Run Code Online (Sandbox Code Playgroud)

环境

// The file contents for the current environment will overwrite these during build.
// The build system defaults to the dev environment which uses `environment.ts`, but if you do
// `ng build --env=prod` then `environment.prod.ts` will be used instead.
// The list of which env maps to which file can be found in `.angular-cli.json`.

export const environment = {
  production: false,
  envName: 'dev',
  // apiUrl: 'https://sp.ipsator.com:8443/api/v1/',
  // publicUrl: 'https://sp.ipsator.com:8443/api/v1/'
  apiUrl: 'v1/',
  publicUrl: 'v1/',
  stationUrl: 'dqoz1bwts/',
  bankUrl: 'utils/'
};
Run Code Online (Sandbox Code Playgroud)

环境产品

export const environment = {
  production: true,
  envName: 'prod',
  apiUrl: 'api/v1/',
  publicUrl: 'api/v1/',
  stationUrl: 'dqoz1bwts/',
  bankUrl: 'utils/'
};
Run Code Online (Sandbox Code Playgroud)

angular.json

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "nitrogen": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist",
            "index": "src/index.html",
            "main": "src/main.ts",
            "tsConfig": "src/tsconfig.app.json",
            "polyfills": "src/polyfills.ts",
            "assets": [
              "src/assets",
              "src/favicon.ico"
            ],
            "styles": [
              "node_modules/ngx-toastr/toastr.css",
              "node_modules/ngx-bootstrap/datepicker/bs-datepicker.css",
              "src/assets/styles/styles.scss"
            ],
            "scripts": [
              "node_modules/jquery/dist/jquery.js",
              "node_modules/bootstrap/dist/js/bootstrap.js"
            ]
          },
          "configurations": {
            "production": {
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "nitrogen:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "nitrogen:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "nitrogen:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "karmaConfig": "./karma.conf.js",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.spec.json",
            "scripts": [
              "node_modules/jquery/dist/jquery.js",
              "node_modules/bootstrap/dist/js/bootstrap.js"
            ],
            "styles": [
              "node_modules/ngx-toastr/toastr.css",
              "node_modules/ngx-bootstrap/datepicker/bs-datepicker.css",
              "src/assets/styles/styles.scss"
            ],
            "assets": [
              "src/assets",
              "src/favicon.ico"
            ]
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "src/tsconfig.app.json",
              "src/tsconfig.spec.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    },
    "nitrogen-e2e": {
      "root": "",
      "sourceRoot": "e2e",
      "projectType": "application",
      "architect": {
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "./protractor.conf.js",
            "devServerTarget": "nitrogen:serve"
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "e2e/tsconfig.e2e.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    }
  },
  "defaultProject": "nitrogen",
  "schematics": {
    "@schematics/angular:component": {
      "prefix": "admin",
      "styleext": "scss"
    },
    "@schematics/angular:directive": {
      "prefix": "admin"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

Stage.json

yarn build:prod

sed -i '' -e "s|/admin/|http://nitrogen-assets.s3-website.ap-south-1.amazonaws.com/admin/|g" dist/index.html
Run Code Online (Sandbox Code Playgroud)

错误截图 在此处输入图片说明

tcs --version

在此处输入图片说明

tcs帮助

在此处输入图片说明

Ric*_*tas 5

我遇到了同样的错误,看来Angular团队改变了命令的工作方式

我以前用过这个:

ng b -prod -e devserver
Run Code Online (Sandbox Code Playgroud)

现在更新的命令是这样的:

ng b --prod --c devserver
Run Code Online (Sandbox Code Playgroud)

观察到-prod更改为--prod,-e(或-environment)更改为-c(或-configuration)

希望能帮助到你

附加信息:https : //medium.com/@beeman/how-to-do-x-in-angular-cli-v6-db7530c23066