angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

How to avoid duplication in configuration?

Open shabinpshams opened this issue 6 years ago • 5 comments

I am using Angular version 9 using nx workspace. I have 5 different projects along with 11 different configurations per project.

How can I eliminate the reusable configurations like aot:true

image

shabinpshams avatar Apr 06 '20 12:04 shabinpshams

You can achieve this by providing multiple configurations.

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

Example ng build --configuration=production,feature

See: https://angular.io/guide/workspace-config#alternate-build-configurations

alan-agius4 avatar Apr 06 '20 17:04 alan-agius4

You can achieve this by providing multiple configurations.

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

Example ng build --configuration=production,feature

See: https://angular.io/guide/workspace-config#alternate-build-configurations

Thanks for your response.

What I asked is how to eliminate

"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true

In all the configuration. Since I have more that 5 production deployments.

shabinpshams avatar Apr 08 '20 11:04 shabinpshams

Hi @shabinpshams, as shown in the above example.

By listing common options in configuration namedproduction in this case and overridden options in another configuration named feature.

Then provide multiple comma-separated configurations in the configuration CLI option.

Ex:

ng build --configuration=production,feature
ng build --configuration=production,feature-foo

The command parses the named configurations from left to right. If multiple configurations change the same setting, the last-set value is the final one.

alan-agius4 avatar Apr 08 '20 12:04 alan-agius4

Hi @shabinpshams, as shown in the above example.

By listing common options in configuration namedproduction in this case and overridden options in another configuration named feature.

Then provide multiple comma-separated configurations in the configuration CLI option.

Ex:

ng build --configuration=production,feature
ng build --configuration=production,feature-foo

The command parses the named configurations from left to right. If multiple configurations change the same setting, the last-set value is the final one.

Thanks again

But it showing error like

image

And I am using ngx-build-plus to build.

shabinpshams avatar Apr 15 '20 14:04 shabinpshams

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.