Home > Net >  nx lib responsible for environment fileReplacements not working
nx lib responsible for environment fileReplacements not working

Time:02-17

  • I have this lib, @my-proj/common which export * from './lib/environment'; in its index.ts
  • my frontend (ng) and backend(express // nest) apps import { environment } from '@my-proj/common';
  • when I build these apps only dev vars are used. ie npx nx build angular-app --prod;
  • I thought since I was building with the prod flag it would use environment.prod.ts from @my-proj/common ?

Project configuration:

"common": {
  "root": "libs/common",
  "sourceRoot": "libs/common/src",
  "projectType": "library",
  "architect": {
    "build": {
      "builder": "@nrwl/node:package",
      "outputs": ["{options.outputPath}"],
      "configurations": {
        "production": {
          "fileReplacements": [
            {
              "replace": "libs/common/src/lib/environment.ts",
              "with": "libs/common/src/lib/environment.prod.ts"
            }
          ]
        }
      },
      "options": {
        "outputPath": "dist/libs/common",
        "tsConfig": "libs/common/tsconfig.lib.json",
        "packageJson": "libs/common/package.json",
        "main": "libs/common/src/index.ts",
        "assets": ["libs/common/*.md"]
      }
    }
  },
  "tags": []
}

CodePudding user response:

it's not possible to do file replacement on libs. You could do the file replacements from the app configuration or make for example your lib configurable with a static forRoot method in the exposed module

  • Related