Skip to content

Modern defaults when creating new angular application with strict flag #17589

Closed
@prabh-62

Description

@prabh-62

🚀 Feature request

Command (mark with an x)

  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • xi18n
  • run
  • config
  • help
  • version
  • doc

Description

When creating angular application with strict flag on, user still needs to update config files to strictest settings.

Here is a list of steps:

  • > npx @angular/[email protected] new ui-applications --createApplication=false --strict=true
  • > cd ui-applications
  • > yarn ng generate application admin-console --defaults=true

Post actions after app is created

  1. Edit angular.json and add OnPush as the default change detection strategy
    "@schematics/angular:component": {
            "changeDetection": "OnPush"
     }

1 angular-onpush

  1. Edit angular.json and update budgets
    		  {
    		   "type": "initial",
    		   "maximumWarning": "500kb",
    		   "maximumError": "600kb"
    		  }	
    2 angular-budgets
  1. Edit tsconfig.json and set strict flag to true
          {
            "compilerOptions": {
              "strictNullChecks": true,
              "strict": true
            }
          }
    3 tsconfig-strict
  1. Edit tsconfig.json and set strictTemplates flag to true
    "angularCompilerOptions": {
      "strictTemplates": true
     }
    4 tsconfig-strictTemplates
  1. Edit tslint.json and add accessibility rules from https://web.dev/accessible-angular-with-codelyzer/
       "template-accessibility-alt-text": true,
       "template-accessibility-elements-content": true,
       "template-accessibility-label-for": true,
       "template-accessibility-tabindex-no-positive": true,
       "template-accessibility-table-scope": true,
       "template-accessibility-valid-aria": true,
       "template-click-events-have-key-events": true,
       "template-mouse-events-have-key-events": true,
       "template-no-autofocus": true,
       "template-no-distracting-elements": true
    5 codelyzer-a11y
  1. Edit projects/admin-console/.browserslistrc and target modern browsers
         last 2 Edge versions
         last 2 Chrome versions
         last 2 Firefox versions
         last 2 Safari versions
    
    6 browserlist
  1. Edit package.json add lint, test and build scripts for admin-console project
       "test:admin-console": "ng test --project admin-console",
       "lint:admin-console": "ng lint --project admin-console",
       "build:admin-console": "ng build --prod --project admin-console"
    7 package-scripts

I ran yarn lint:admin-console and yarn build:admin-console after making these changes(also, deleted contents of app.component.html) and I had no issues.
9 yarn build_admin-console

Describe the solution you'd like

If angular-cli could expose a modern (or something alike) flag, that would save developer time. It becomes very tedious to introduce these flags at a later stage when the team of developers is actively working on projects.

  • > npx @angular/[email protected] new ui-applications --createApplication=false --strict=true --modern=true

Describe alternatives you've considered

I manually update config files for now

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions