如何根据环境更改 scss 样式?

How to change scss styles based on environment?

我正在尝试根据环境更改 style.scss。我尝试将这两个属性添加到 angular.json 但它们都没有解决我的问题:

   "styles": [
                {
                   "input": "generic/src/styles.scss"
                }
             ],
   "stylePreprocessorOptions": {
                       "includePaths": [
                                         "generic/src"
                                       ]
                               },

这是我当前的目录:

我的也是 angular.json:

"generic-payment-portal-fe": {
      "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",
              "src/web.config",
              "src/godaddy.html"
            ],
            "styles": [
              "src/styles.scss"
            ],
            "scripts": []
          },
          "configurations": {
            "test": {
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "styles": [
                {
                  "input": "generic/src/styles.scss"
                }
              ],
              "stylePreprocessorOptions": {
                "includePaths": [
                  "generic/src"
                ]
              },
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "generic/src/environments/environment.test.ts"
                },
                {
                  "replace": "src/favicon.ico",
                  "with": "generic/src/favicon.ico"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "generic-payment-portal-fe:build"
          },
          "configurations": {
            "test": {
              "browserTarget": "generic-payment-portal-fe:build:test"
            }
          },
          "fileReplacements": [
            {
              "replace": "src/environments/environment.test.ts",
              "with": "generic/src/environments/environment.test.ts"
            },
            {
              "replace": "src/assets/img/header__logo.svg",
              "with": "generic/src/assets/img/header__logo.svg"
            }
          ]
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "generic-payment-portal-fe: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": [],
            "styles": [
              "src/styles.scss"
            ],
            "assets": [
              "src/assets",
              "src/favicon.ico",
              "src/web.config"
            ]
          }
        }
      }
    },
    "expensas-pagas-payment-portal-fe": {
      "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",
              "src/web.config",
              "src/godaddy.html"
            ],
            "styles": [
              "src/styles.scss"
            ],
            "scripts": []
          },
          "configurations": {
            "dev": {
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true
            },
            "test": {
              "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.test.ts"
                }
              ]
            },
            "prod": {
              "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"
                },
                {
                  "replace": "src/web.config",
                  "with": "src/web.prod.config"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "expensas-pagas-payment-portal-fe:build"
          },
          "configurations": {
            "test": {
              "browserTarget": "expensas-pagas-payment-portal-fe:build:test"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "expensas-pagas-payment-portal-fe: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": [],
            "styles": [
              "src/styles.scss"
            ],
            "assets": [
              "src/assets",
              "src/favicon.ico",
              "src/web.config"
            ]
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "src/tsconfig.app.json",
              "src/tsconfig.spec.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    },

我读了一些书,但没有找到任何关于为什么它不采用这些样式的信息,但是,图标和网站图标的更改正确地做到了。我用来 运行 解决方案的命令如下:

您应该能够像 environment/favicon

那样更新 fileReplacements
"fileReplacements": [
  {
    "replace": "src/environments/environment.ts",
    "with": "generic/src/environments/environment.test.ts"
  },
  {
    "replace": "src/favicon.ico",
    "with": "generic/src/favicon.ico"
  },
  {
    "replace": "src/style.scss",
    "with": "generic/src/style.scss"
  }
]