Setting default config elements in Angular 6 w/ NX
Was having some trouble with the schematics generator using nrwl’s NX in a monorepo, as my preferred defaults weren’t getting generated.
It’s performance-destroying to have to make sure you remember to set changeDetection to OnPush in every component if you’re using ngrx like I am (and forget). It’s also something I haven’t been able to figure out how to search for…the absence of a changeDetection strategy in a selector…would love a comment if you know how to do this (I’d imagine offhand you could lint this)
Here’s the issue that pointed me to the fix: https://github.com/nrwl/nx/issues/533
If you’re using NX, then the schematics configuration isn’t set by
@schematics:component
Instead it’s set by
@nrwl/schematics:component
So I added the following to the bottom of my angular.json and now I’m getting the right auto-generated settings
//angular.json"cli": { "warnings": { "typescriptMismatch": false, "versionMismatch": false},"defaultCollection": "@nrwl/schematics"},"defaultProject": "app1","schematics": { "@nrwl/schematics:component": { "styleext": "scss", "spec": true, "flat": true, "changeDetection": "OnPush", "prefix": "my-prefix" }}