Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fileReplacements in angular.cli serve configuration

I have a requirement to replace files in my Angular application using fileReplacements, but it seems that this is only available in build configurations, and not serve configurations.

Here is an extract of my angular.json:

"serve": {
  "builder": "@angular-devkit/build-angular:dev-server",
  "options": {
    "browserTarget": "SupplierPortal:build"
  },
  "configurations": {
    "production": {
      "browserTarget": "SupplierPortal:build:production"
    },
    "fr": {
      "fileReplacements": [
        {
          "replace": "src/environments/environment.ts",
          "with": "src/environments/environment.fr.ts"
        }
      ],
      "browserTarget": "SupplierPortal:build:fr"
    }
}

But the compiler complains:

Schema validation failed with the following errors:

Data path "" should NOT have additional properties(fileReplacements).

Is it possible to have configurations for various serve builds?

like image 973
serlingpa Avatar asked Apr 25 '19 15:04

serlingpa


People also ask

What is angular CLI json file?

A file named angular. json at the root level of an Angular workspace provides workspace-wide and project-specific configuration defaults for build and development tools provided by the Angular CLI. Path values given in the configuration are relative to the root workspace folder.

What is environment TS file in angular?

A project's src/environments/ folder contains the base configuration file, environment. ts , which provides a default environment. You can add override defaults for additional environments, such as production and staging, in target-specific configuration files. For example: myProject/src/environments.

Where is angular CLI json located?

The angular-cli. json should be located in the root folder of the project.


1 Answers

You almost got it. After specifying the fileReplacements in your build configurations, just need to tell to the serve configuration which build config to use.

Then you can execute ng serve -c=fr and the serve will apply the fr build configuration:

{
  "build": {
    "builder": "@angular-devkit/build-angular:browser",
    "configurations": {
      "fr": {
        "fileReplacements": [{
          "replace": "src/environments/environment.ts",
          "with": "src/environments/environment.fr.ts"
        }]
      }
    }
  },
  "serve": {
    "builder": "@angular-devkit/build-angular:dev-server",
    "options": {
      "browserTarget": "SupplierPortal:build"
    },
    "configurations": {
      "production": {
        "browserTarget": "SupplierPortal:build:production"
      },
      "fr": {
        "browserTarget": "SupplierPortal:build:fr"
      }
    }
  }
}
like image 87
artemisian Avatar answered Oct 07 '22 00:10

artemisian