Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add global configuration for the default change detection and styles encapsulation settings #55023

Open
galczo5 opened this issue Mar 22, 2024 · 2 comments
Labels
area: compiler Issues related to `ngc`, Angular's template compiler
Milestone

Comments

@galczo5
Copy link

galczo5 commented Mar 22, 2024

Which @angular/* package(s) are relevant/related to the feature request?

compiler-cli

Description

At the moment as a developer when I want to use ChangeDetectionStrategy.OnPush in the whole project, I need to add it to every component. It generates one more line and additional import and it's not intuitive.

Would be great to have an option to set it globally and reduce number of lines in @Component decorator.

Proposed solution

As far as I understand, it needs to set during compilation process, so probably the most obvious place to put configuration is angular.json

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "experiment-signal-input": {
      // ...
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:application",
          "options": {
            "changeDetection": "OnPush", // <---
            "encapsulation": "None", // <---
            "outputPath": "dist/experiment-signal-input",
            // ...
          },
          "defaultConfiguration": "production"
        }
      }
    }
  }
}

The main problem that I see at the moment is that it shouldn't affect third party libraries from node_modules.

Alternatives considered

Make the ChangeDetectionStrategy.OnPush as default, but it will harm onboarding and it sounds bad that ChangeDetectionStrategy.Default is not the default option. So I wouldn't consider it :D

@ngbot ngbot bot modified the milestone: needsTriage Mar 22, 2024
@alan-agius4 alan-agius4 transferred this issue from angular/angular Mar 25, 2024
@alan-agius4 alan-agius4 transferred this issue from angular/angular-cli Mar 25, 2024
@alan-agius4 alan-agius4 added the area: compiler Issues related to `ngc`, Angular's template compiler label Mar 25, 2024
@ngbot ngbot bot added this to the needsTriage milestone Mar 25, 2024
@JeanMeche
Copy link
Member

Like you said, global settings would also affect the libraries which could potentially break them.
You currently alternative it to set the schematics to only generate OnPush components.

@galczo5
Copy link
Author

galczo5 commented Mar 26, 2024

What about setting a scope using pattern for OnPush components? Wouldn't it solve the problem? It's a bit more complicated, but still reduces number of lines in @Component decorator.
For example:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "experiment-signal-input": {
      // ...
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:application",
          "options": {
            "changeDetection": [{
              "value": "OnPush",
              "pattern": "src/**/*.component.ts"
            }],
            "outputPath": "dist/experiment-signal-input",
            // ...
          },
          "defaultConfiguration": "production"
        }
      }
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: compiler Issues related to `ngc`, Angular's template compiler
Projects
None yet
Development

No branches or pull requests

3 participants