25

在 Angular 5 中,我们可以使用

ng build --prod --env=uat

迁移到 Angular 6 后,上述命令会引发错误

Unknown option: '--env'
4

5 回答 5

38

需要使用配置选项

ng build --prod --configuration=uat

或者

ng build --prod -c uat

更多信息在这里

同样对于 ng 服务与此处回答的选项相同

于 2018-05-10T05:42:00.410 回答
8

我已经在 Angular 6 项目中进行了测试。

ng build --prod --configuration=uat似乎不起作用,因为它仅在您运行此命令时选择 uat 配置并忽略--prod标志并且不应用任何优化,例如 aot、缩小和升级等。

跑步ng build --prod --configuration=uat的效果和只跑步一样ng build --configuration=uat。为了应用任何其他配置选项,我们需要在 angular.json 的 uat 构建选项中显式添加它们

"configurations": {
        "production": {
          "fileReplacements": [
            {
              "replace": "src/environments/environment.ts",
              "with": "src/environments/environment.prod.ts"
            }
          ],
          "optimization": true,
          "outputHashing": "all",
          "sourceMap": false,
          "extractCss": true,
          "namedChunks": false,
          "aot": true,
          "extractLicenses": true,
          "vendorChunk": false,
          "buildOptimizer": true
        },
        "uat": {
          "fileReplacements": [
            {
              "replace": "src/environments/environment.ts",
              "with": "src/environments/environment.test.ts"
            }
          ],
          "optimization": true,
          "outputHashing": "all",
          "sourceMap": false,
          "extractCss": true,
          "namedChunks": false,
          "aot": true,
          "extractLicenses": true,
          "vendorChunk": false,
          "buildOptimizer": true
        }
      }
    }
于 2019-01-27T18:31:17.527 回答
2

你可以尝试使用:

ng build --configuration=uat
于 2019-10-01T11:35:29.307 回答
1

你可以尝试使用

ng build ---产品

于 2018-05-24T07:52:47.263 回答
0
Prod: ng build --prod
Qa: ng build --configuration=qa

angular.json
"production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ]
},
"qa": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.qa.ts"
                }
              ]
}

PROD:
export const environment = {
  production: true,
  api : 'https://example.com'
}

QA:
export const environment = {
    production: true,
    api : 'https://example-Qa.com'
}

dev environment
export const environment = {
    production:false,
    api : 'https://example-dev.com'
}
于 2020-06-13T06:59:51.537 回答