Home > Enterprise >  Publishing angular 8 site using a configuration does not work
Publishing angular 8 site using a configuration does not work

Time:06-28

I have an angular 8 site and I am trying to publish it locally and then deploy it. During the build step I specify an environment name that I have defined as internalprod:

src
├───app
├───environments
│       environment.Debug.ts
│       environment.InternalProd.ts
│       environment.PreLive.ts
│       environment.prod.ts
│       environment.Test.ts
│       environment.ts
└───js

environment.InternalProd.ts

export const environment = {
...
  environmentName: "InternalProd"
};

angular.json

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
...
          "configurations": {
...
            "internalprod": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.InternalProd.ts"
                }
              ],
              "baseHref": "/",
              "deployUrl": "/",
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": true,
              "commonChunk": true,
              "buildOptimizer": true,
              "poll": 500
            },
...
}

To build the project I cd into the src dir and use the command npm run ng build --configuration=internalprod

However, when I inspect the dist/myproject/main-es5.js and dist/myproject/main-es2015.js files and navigate to the var environment = section I do not see the variables being replaced with the internalProd configuration file:

    var environment = {
      ...
      environmentName: "Development"
      }
    };

Apparently, the environment.Debug.ts file gets picked up as this is the only file setting the environmentName var to Development but I do not understand why that happens.

CodePudding user response:

According to this post you may execute your command starting with two dashes npm run ng build -- --configuration=internalprod and probably outside the src folder.

Cheers!

  • Related