1

I have a little (maybe big) problem with an angular application when hot reload hits

First time the application loads the correct resources with the correct path are loaded :

http://localhost:4200/styles.css
http://localhost:4200/styles.js
....

When I edit a component say for example 'VoiceComponent' and the current link is http://localhost:4200/voices/ the application will reload but the resources loaded are

http://localhost:4200/voices/styles.css
http://localhost:4200/styles.js
....

Same thing if I edit a 'HelloComponent' and the current link is http://localhost:4200/hello/ the application will relaod but yhe resources loaded are

http://localhost:4200/hello/styles.css
http://localhost:4200/styles.js
....

The application tries to load styles.css in relative to the current path

angular.json:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "nobleui-angular": {
      "projectType": "application",
      "schematics": {
        "@schematics/angular:component": {
          "style": "scss"
        }
      },
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "aot": false,
            "assets": [
              "src/favicon.ico",
              "src/assets",
              "src/.htaccess"
            ],
            "styles": [
              "src/styles.scss",
              "src/assets/scss/style.scss"
              
            ],
            "scripts": [
              "node_modules/apexcharts/dist/apexcharts.min.js"
            ]
          },
          "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,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb",
                  "maximumError": "10kb"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "nobleui-angular:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "nobleui-angular:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "nobleui-angular:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.spec.json",
            "karmaConfig": "karma.conf.js",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.scss"
            ],
            "scripts": []
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "tsconfig.app.json",
              "tsconfig.spec.json",
              "e2e/tsconfig.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        },
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "nobleui-angular:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "nobleui-angular:serve:production"
            }
          }
        }
      }
    }
  },
  "defaultProject": "nobleui-angular",
  "cli": {
    "analytics": false
  }
}

Any help would be appreciated

1 Answer 1

3

I found the problem :

I didn't close the <head> tag in index.html .. so the <base href="/"> inside wasn't working

Sign up to request clarification or add additional context in comments.

2 Comments

I just ran into the same problem, this solved it! Thanks
This should be upvoted umpteen times !! Without <head>, <base> tag doesn't work !! thanks for helping

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.