angular style.scss 在浏览器中未更新。

huangapple go评论90阅读模式
英文:

angular style.scss not updated in the browser

问题

在我的Angular项目中,我不再能够在style.scss文件中添加代码,当我添加新的代码行时,它不会生效,当我在浏览器中检查时,添加的行在源文件中不存在。
我尝试清除缓存并在不同的服务器上启动应用程序,但行为仍然相同。代码存在于我的文件中,但在浏览器中缺失。对于订单组件样式,它可以正常工作;问题只出现在全局文件样式或在angular.json的样式数组中导入的情况下。
这是我的angular.json配置:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "position-web": {
      "projectType": "application",
      "schematics": {
        "@schematics/angular:component": {
          "style": "scss"
        }
      },
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "allowedCommonJsDependencies": [
              "maplibre-gl"
            ],
            "outputPath": "dist/position-web",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": [
              "zone.js"
            ],
            "tsConfig": "tsconfig.app.json",
            "inlineStyleLanguage": "scss",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.scss"
            ],
            "scripts": []
          },
          "configurations": {
            "production": {
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "9mb",
                  "maximumError": "9mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "500kb",
                  "maximumError": "500kb"
                }
              ],
              "outputHashing": "all"
            },
            "development": {
              "buildOptimizer": false,
              "optimization": false,
              "vendorChunk": true,
              "extractLicenses": false,
              "sourceMap": true,
              "namedChunks": true
            }
          },
          "defaultConfiguration": "production"
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "configurations": {
            "production": {
              "browserTarget": "position-web:build:production"
            },
            "development": {
              "browserTarget": "position-web:build:development"
            }
          },
          "defaultConfiguration": "development"
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "position-web:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "polyfills": [
              "zone.js",
              "zone.js/testing"
            ],
            "tsConfig": "tsconfig.spec.json",
            "karmaConfig": "karma.conf.js",
            "inlineStyleLanguage": "scss",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.scss"
            ],
            "scripts": [
              "node_modules/flatpickr/dist/flatpickr.min.js"
            ]
          }
        },
        "lint": {
          "builder": "@angular-eslint/builder:lint",
          "options": {
            "lintFilePatterns": [
              "src/**/*.ts",
              "src/**/*.html"
            ]
          }
        }
      }
    }
  },
  "cli": {
    "analytics": "b15adbd6-08c2-46b2-ac4d-d01914c62569"
  }
}

注意:请确保在style.scss文件中添加的代码是正确的,并且没有语法错误。如果代码正确但仍然不生效,请尝试清除浏览器缓存或重新启动开发服务器。

英文:

In my angular project am mot longer able to add code in style.scss file, when i add a new line of code it's not applied and when i inpect in the browser the added line is missing in the source.
I tried to clear the cash and lunch the app in a different server but is still the same behavior . the code is present in my file but absent in the browser. for the order component style it works without problem ; the issue is just with the global file style or import in the style array of angular.json.
This is my angular.json config

{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"position-web": {
"projectType": "application",
"schematics": {
"@schematics/angular:component": {
"style": "scss"
}
},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"allowedCommonJsDependencies": [
"maplibre-gl"
],
"outputPath": "dist/position-web",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": [
"zone.js"
],
"tsConfig": "tsconfig.app.json",
"inlineStyleLanguage": "scss",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.scss"
],
"scripts": []
},
"configurations": {
"production": {
"budgets": [
{
"type": "initial",
"maximumWarning": "9mb",
"maximumError": "9mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "500kb",
"maximumError": "500kb"
}
],
"outputHashing": "all"
},
"development": {
"buildOptimizer": false,
"optimization": false,
"vendorChunk": true,
"extractLicenses": false,
"sourceMap": true,
"namedChunks": true
}
},
"defaultConfiguration": "production"
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"configurations": {
"production": {
"browserTarget": "position-web:build:production"
},
"development": {
"browserTarget": "position-web:build:development"
}
},
"defaultConfiguration": "development"
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "position-web:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"polyfills": [
"zone.js",
"zone.js/testing"
],
"tsConfig": "tsconfig.spec.json",
"karmaConfig": "karma.conf.js",
"inlineStyleLanguage": "scss",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.scss"
],
"scripts": [
"node_modules/flatpickr/dist/flatpickr.min.js"
]
}
},
"lint": {
"builder": "@angular-eslint/builder:lint",
"options": {
"lintFilePatterns": [
"src/**/*.ts",
"src/**/*.html"
]
}
}
}
}
},
"cli": {
"analytics": "b15adbd6-08c2-46b2-ac4d-d01914c62569"

}
}

答案1

得分: 1

  1. 尝试进行强制刷新(大多数浏览器上是Ctrl + Shift + R),以确保浏览器获取样式表的最新版本。

  2. 尝试重命名style.scss: 作为测试,尝试将style.scss文件重命名为不同的名称,并在angular.json中更新引用。然后,在重命名的文件中添加一些新的样式,看看它们是否生效。

  3. 检查CSS覆盖: 使用浏览器的开发者工具检查应用于特定元素的样式。查看是否有任何可能覆盖在style.scss中定义的样式的CSS规则。CSS特异性和样式表加载顺序可能导致样式冲突。

  4. 检查CSS Linting错误: 如果您正在使用CSS linting工具,请验证styles.scss文件中是否没有可能阻止样式生效的linting错误或警告。

英文:
  1. Try doing a hard reload (Ctrl + Shift + R on most browsers) to ensure that the browser fetches the latest version of the stylesheet.

  2. Try Renaming style.scss: As a test, try renaming the style.scss file to a different name and update the reference in angular.json. Then, add some new styles in the renamed file and see if they are applied.

  3. Inspect CSS Overrides: Use your browser's developer tools to inspect the styles applied to specific elements. Check for any CSS rules that might be overriding the styles you defined in style.scss. CSS specificity and order of stylesheet loading can lead to style conflicts.

  4. Check for CSS Linting Errors: If you are using CSS linting tools, verify that there are no linting errors or warnings in your styles.scss file that might prevent the styles from being applied.

huangapple
  • 本文由 发表于 2023年7月20日 13:26:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/76726901.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定