【问题标题】:Angular environment for many stagings许多阶段的角度环境
【发布时间】:2021-02-22 22:41:04
【问题描述】:

我为部署构建版本,需要为 prod、staging1 和 staging2 配置配置。 我在环境文件夹中有文件:

environments.ts
environments.prod.ts
environments.staging1.ts
environments.staging2.ts

在 Angular.json 我有部分:

"configurations": {
            "prod": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
            "staging1": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.staging1.ts"
                }
              ]
            },
            "staging2": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.staging2.ts"
                }
              ]
            }

当我像这样调用命令时:

call npm install
call npm run prod --configuration staging1

它仍然需要第一个环境文件:environment.prod.ts 文件,而不是 environment-staging1.ts


在 package.json 我有这样的构建命令:

{
  "name": "finant",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "node start.js && ng serve",
    "build": "node pre-build.js && ng build --configuration=prod --output-hashing=none --extra-webpack-config webpack.extra.js",
    "prod": "npm run build && node build.js",

这是个问题,因为当我更改为 --configuration=staging1 时它可以工作,但我必须手动更改它

【问题讨论】:

    标签: angular npm


    【解决方案1】:

    为此,您需要使用 double -- 传递配置

    npm run prod -- --configuration staging1
    

    【讨论】:

    • 我在帖子中添加了评论
    • 上述命令不起作用,因为它仍然使用 --configuration=prod 从 package.json 调用 build
    猜你喜欢
    • 1970-01-01
    • 2012-09-03
    • 1970-01-01
    • 2018-04-20
    • 2021-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多