3

When building angular 6 app, the scripts files are generated and so the css file. All the files have the hashed value in the end.

Is it possible to modify the index.html links for these files? The path is always local file but if i upload them on some server i want for example tho add a custom variable url i have in environment.prod.json.

2
  • 2
    You don't need to: the index.html file is also generated, and contains scripts that refer to the scripts and css files that have been generated. Look in your dist folder. Commented Aug 11, 2018 at 13:46
  • 1
    This behavior is controlled to some extent by Angular CLI (github.com/angular/angular-cli/wiki/build). Check out options --base-href and --deploy-url. Hashes are controlled by --output-hashing. Commented Aug 11, 2018 at 14:25

2 Answers 2

2

Yes you can create a custom index.html (e.g. index.prod.html) for each environment:

Create in your src folder another copy of index.html (index.prod.html) include any custom links you need in that index for that environment and inside angular.json add the following (the fileReplacement part):

      "configurations": {
        "production": {
          "optimization": true,
          "outputHashing": "all",
          "sourceMap": false,
          "extractCss": true,
          "namedChunks": false,
          "aot": true,
          "extractLicenses": true,
          "vendorChunk": false,
          "buildOptimizer": false,
          "fileReplacements": [
            {
              "replace": "src/environments/environment.ts",
              "with": "src/environments/environment.prod.ts"
            },
            {
              "replace": "src/index.html",
              "with": "src/index.prod.html"
            }
          ]
        },

Please note this options is fixed and working on Angular 6.1 before that you couldn't use the fileReplacements for index files.

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

Comments

0

Following @Mark Uretsky answer from angular 8 version you shouldn't use fileReplacements.

Please use this:

      "index": {
        "input": "src/index.prod.html",
        "output": "index.html" // specify the path you want index.html to be generated.
      }

Comments

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.