未知选项:“-target”,未知选项:“-environment”;尝试在产品中构建ng应用时

时间:2019-04-02 05:58:13

标签: angular typescript build ng-build

试图在生产模式下构建角度应用,但发现未知的目标和环境错误。

尝试以下方法:

ng build --target=production --base-href /
ng build --target=production --environment=prod
ng build --prod --env=prod

我希望构建文件如main.js,vendor.js等。 输出是:

Unknown option: '--target'
Unknown option: '--environment'

4 个答案:

答案 0 :(得分:0)

发现以下命令在没有任何参数的情况下执行良好:

ng build --prod

输出:

Date: 2019-04-02T05:51:07.034Z
Hash: 13d7def367e6ab28002d
Time: 126225ms
chunk {0} runtime.26209474bfa8dc87a77c.js (runtime) 1.41 kB [entry] [rendered]
chunk {1} es2015-polyfills.c5dd28b362270c767b34.js (es2015-polyfills) 56.4 kB [initial] [rendered]
chunk {2} main.ab6e55257ccc1317a780.js (main) 245 kB [initial] [rendered]
chunk {3} polyfills.8bbb231b43165d65d357.js (polyfills) 41 kB [initial] [rendered]
chunk {4} styles.b0dcfc0155d6280ef171.css (styles) 488 kB [initial] [rendered]

答案 1 :(得分:0)

您可以使用此构建命令 ng build --base-href="/" --env=prod

答案 2 :(得分:0)

ng build --prod是生产环境的默认构建命令,无需其他参数,仅在需要实现某些特定条件时 例如,如果您有其他环境,则可以运行

ng build --c= staging,其中c代表配置 这是其他选择 https://angular.io/cli/build

答案 3 :(得分:0)

ng build --configuration=staging
ng server --configuration=staging

确保在环境文件夹中创建一个environment.staging文件,并且还修改了angular.json文件以允许该命令。

"build": {
"production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ]
            },
            "staging": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.staging.ts"
                }
              ]
            }
}
    

"serve": {
      "builder": "@angular-devkit/build-angular:dev-server",
      "options": {
        "browserTarget": "letsfarm-frontend:build"
      },
      "configurations": {
        "production": {
          "browserTarget": "letsfarm-frontend:build:production"
        },
        "staging": {
          "browserTarget": "letsfarm-frontend:build:staging"
        }
      }
    },