question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Replace index.html, favicon.ico with `fileReplacements` option

See original GitHub issue

Expected Behavior

fileReplacements would replace an index.html file if specified

Current Behavior

What is the current behavior? File replacements only seems to work with .ts files.

Failure Information (for bugs)

Not sure where to find logs for this.

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

npx create-nx-workspace@latest repro-workspace

nx add @nrwl/react

nx g @nrwl/react:app f5

Add apps/f5/src/environments/one-word-story.ts and apps/f5/src/one-word-story-index.html

update build to match this angular.json snippet

   "f5": {
      "root": "apps/f5",
      "sourceRoot": "apps/f5/src",
      "projectType": "application",
      "schematics": {},
      "architect": {
        "build": {
          "builder": "@nrwl/web:build",
          "options": {
            "outputPath": "dist/apps/f5",
            "index": "apps/f5/src/index.html",
            "main": "apps/f5/src/main.tsx",
            "polyfills": "apps/f5/src/polyfills.ts",
            "tsConfig": "apps/f5/tsconfig.app.json",
            "assets": ["apps/f5/src/favicon.ico", "apps/f5/src/assets"],
            "styles": ["apps/f5/src/styles.scss"],
            "scripts": [],
            "webpackConfig": "@nrwl/react/plugins/webpack"
          },
          "configurations": {
            "one-word-story": {
              "outputPath": "dist/apps/one-word-story",
              "fileReplacements": [
                {
                  "replace": "apps/f5/src/environments/environment.ts",
                  "with": "apps/f5/src/environments/one-word-story.ts"
                },
                {
                  "replace": "apps/f5/src/index.html",
                  "with": "apps/f5/src/one-word-story-index.html"
                },
             ]
           }
         }
       }
     }

nx run f5:build:one-word-story

If you can provide steps to reproduce from scratch, that would be enormously appreciated (i.e. where the first step is npx create-nx-workspace@latest repro-workspace)

Context

My use case is I’d like to generate different bundles for different customers without having to create a project for each customer. The differences between each customer’s site is just index.ts, favicon.ico, and environment.ts.

Please provide any relevant information about your setup:

  @nrwl/cli : 8.11.2

Failure Logs

Not sure where to find these.

Other

Thanks for the great tool.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

4reactions
xiongemicommented, Mar 11, 2021

to replace index.html, i got it work this way:

 "configurations": {
            "production": {
              "index": "<path to index.prod.html>",
2reactions
Stupidismcommented, Aug 16, 2020

I encountered this problem, too. I had a prod.ico and wanted to replace favicon.ico in production like this:

"fileReplacements": [
                {
                  "replace": "apps/storage-ui/src/assets/favicon.ico",
                  "with": "apps/storage-ui/src/assets/prod.ico"
                },
...

Of course it didn’t work. I think it’s because the assets folder is overwritten again by the assets option. like this issue described

Here’s my workaround for replacing favicon:

add another production folder inside assets folder and rename my prod.ico as production/favicon.ico

"production": {
              "assets": [
                {
                  "input": "apps/storage-ui/src/assets/production",
                  "glob": "**/*.{css,ico}",
                  "output": "assets"
                }
              ],
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I replace file with property fileReplacements on ...
I have a problem with Angular workspace configuration when I want to replace file, I will provide some information below: My app info:....
Read more >
Favicons for Each Environment - Ben Racicot - Medium
And how would we rename them or update the index.html's favicon src? ... If you got assets configuration to replace favicon.ico with ...
Read more >
Start MockService Instance - Angular - Code with Mosh Forum
I am trying to build an Angular project, that has 4 different build types prod (production, requests go to production Backend) test ...
Read more >
NG9: Unable to add new environment file - Google Groups
I'm using Angular 9 (VS Code in Win 10). Started with the two default environment files. Added a third, environment.qa.ts. Updated angular.json: replacements ......
Read more >
Angular Service Worker - Step-By-Step Guide
Learn all about the multiple PWA caching configuration options of the ... index.html, CSS and Javascript bundles plus the favicon).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found