|
| 1 | +# Angular Schematics - Configuration |
| 2 | + |
| 3 | +Some common options can be customized in a one click with the configuration helper: |
| 4 | + |
| 5 | +- Copy settings from angular.json |
| 6 | +- Enable SCSS, Sass or Less styles ⚙️ |
| 7 | +- Disable styles ⚙️ |
| 8 | +- Enable external HTML templates ⚙️ |
| 9 | +- Enable single file components (SFC) ⚙️ |
| 10 | +- Enable or disable ngOnInit ⚙️ |
| 11 | +- Disable change detection optimization ⚙️ |
| 12 | +- Disable lazy loading ⚙️ |
| 13 | +- Disable block CSS display ⚙️ |
| 14 | +- Enable shadow DOM ⚙️ |
| 15 | +- Set the selector prefix ⚙️ |
| 16 | +- Force NgModules 💎 |
| 17 | +- Force class interceptors 💎 |
| 18 | +- Force class guards and resolvers 💎 |
| 19 | +- Disabled predefined schematics 💎 |
| 20 | + |
| 21 | +⚙️ = in the Pro edition 💎, configurable per Angular project |
| 22 | + |
| 23 | +**You can access the configuration helper at any time from the Angular logo on the left sidebar**, or from the VS Code menu: |
| 24 | +1. View |
| 25 | +2. Command Palette |
| 26 | +3. search "configuration" |
| 27 | +4. choose "Angular Schematics: Configuration helper" |
| 28 | + |
| 29 | +<br> |
| 30 | + |
| 31 | +## Where is configuration stored? |
| 32 | + |
| 33 | +This extension stores the configuration in VS Code *workspace* settings. It means: |
| 34 | +- it is applied only to the current opened project |
| 35 | +- if you commit the `.vscode/settings.json` file (and you should), all your team will benefit from it |
| 36 | +- the configuration helper assists you to set the initial settings, if you want to change them afterwards, just edit the `.vscode/settings.json` file |
| 37 | + |
| 38 | +<br> |
| 39 | + |
| 40 | +## Copy settings from angular.json |
| 41 | + |
| 42 | +This extension uses its own configuration. But if you have an *official and valid* `angular.json` with some `schematics` settings, the extension can copy them. It should detect the following settings: |
| 43 | +- SCSS, Sass or Less styles |
| 44 | +- no style |
| 45 | +- external HTML templates |
| 46 | +- single file components (SFC) |
| 47 | +- change detection optimization |
| 48 | +- shadow DOM |
| 49 | + |
| 50 | +<br> |
| 51 | + |
| 52 | +## Enable SCSS, Sass or Less styles |
| 53 | + |
| 54 | +For projects with a design system still using CSS preprocessors (like SCSS for Angular Material or PrimeNG). |
| 55 | + |
| 56 | +<br> |
| 57 | + |
| 58 | +## Disable styles |
| 59 | + |
| 60 | +For projects not using styles in components and pages because of alternative tools (like Tailwind CSS). |
| 61 | + |
| 62 | +<br> |
| 63 | + |
| 64 | +## Enable external HTML templates |
| 65 | + |
| 66 | +Unlike the Angular CLI, inline HTML templates are the default in this extension because: |
| 67 | +- less files (separation of concerns is not separation of files) |
| 68 | +- it is easier to see the data bindings connections between the HTML and the class |
| 69 | +- it draws attention to the template length, to keep each component as small as possible |
| 70 | +- the official [Angular Language Service extension](https://marketplace.visualstudio.com/items?itemName=Angular.ng-template) provides the same coloration and autocompletion as in HTML files |
| 71 | + |
| 72 | +But you can switch to external HTML templates if you prefer. |
| 73 | + |
| 74 | +<br> |
| 75 | + |
| 76 | +## Enable single file components (SFC) |
| 77 | + |
| 78 | +Some may want to go even further with single file components (inline HTML, inline styles and no subfolder). |
| 79 | + |
| 80 | +<br> |
| 81 | + |
| 82 | +## Enable or disable ngOnInit |
| 83 | + |
| 84 | +By default in this extension: |
| 85 | +- components does not include `ngOnInit()` (because most pure components should not handle such logic) |
| 86 | +- pages includes `ngOnInit()` (because pages have to handle logic) |
| 87 | + |
| 88 | +But you can enable or disable ngOnInit() as you wish. |
| 89 | + |
| 90 | +<br> |
| 91 | + |
| 92 | +## Disable change detection optimization |
| 93 | + |
| 94 | +With the introduction of signals in Angular 16, the good practice is to optimize the change detection strategy of all components and pages to `OnPush`. |
| 95 | + |
| 96 | +If your project uses Angular <=15, or if you or your team are not yet comfortable with these topics, you can disable the change detection optimization in pages and/or in components. |
| 97 | + |
| 98 | +<br> |
| 99 | + |
| 100 | +## Disable lazy loading |
| 101 | + |
| 102 | +By default, for better application performances, pages are generated as lazy loaded components. But you can disable lazy loading. |
| 103 | + |
| 104 | +<br> |
| 105 | + |
| 106 | +## Disable block CSS display |
| 107 | + |
| 108 | +Web components have an `inline` CSS display by default. It is a flaw of the standard, as 99% of components are in fact used as `block`s. So when generating components, `:host { display: block; }` is automatically added in styles, but you can disable it. |
| 109 | + |
| 110 | +<br> |
| 111 | + |
| 112 | +## Enable shadow DOM |
| 113 | + |
| 114 | +For projects ready to use native shadow DOM view encapsulation. |
| 115 | + |
| 116 | +<br> |
| 117 | + |
| 118 | +## Set the selector prefix |
| 119 | + |
| 120 | +Angular default prefix selector for components, directives and pipes is `app`. |
| 121 | + |
| 122 | +If you want a different one, this is the only setting for which the extension uses the official `angular.json` `prefix` configuration, because this one is simple to get and in an Angular CLI monorepo, it can differ from one application or library to another. |
| 123 | + |
| 124 | +<details> |
| 125 | +<summary>Example of angular.json</summary> |
| 126 | + |
| 127 | +```json |
| 128 | +{ |
| 129 | + "version": 1, |
| 130 | + "projects": { |
| 131 | + "some-app": { |
| 132 | + "projectType": "application", |
| 133 | + "prefix": "app" |
| 134 | + }, |
| 135 | + "some-lib": { |
| 136 | + "projectType": "library", |
| 137 | + "prefix": "mycompany", |
| 138 | + } |
| 139 | + } |
| 140 | +} |
| 141 | +``` |
| 142 | +</details> |
| 143 | + |
| 144 | +But it requires a *valid and official* `angular.json`, which is not the case in all projects. Only such cases, set the selector prefix via the extension configuration helper. It will be global to the workspace. |
| 145 | + |
| 146 | +<br> |
| 147 | + |
| 148 | +## 💎 Force NgModules |
| 149 | + |
| 150 | +In the Pro edition, if your project uses Angular <=13 or is not ready for standalone components yet. |
| 151 | + |
| 152 | +<br> |
| 153 | + |
| 154 | +## 💎 Class interceptors |
| 155 | + |
| 156 | +In the Pro edition, if your project uses Angular <=14 or is not ready for functional interceptors yet. |
| 157 | + |
| 158 | +<br> |
| 159 | + |
| 160 | +## 💎 Class guards and resolvers |
| 161 | + |
| 162 | +In the Pro edition, if your project uses Angular <=14.1 or is not ready for functional guards and resolvers yet. Note [class guards and resolvers are officially deprecated](https://angular.io/guide/deprecations#router-class-and-injection-token-guards) by Angular and planned for removal. |
| 163 | + |
| 164 | +<br> |
| 165 | + |
| 166 | +## 💎 Disable predefined schematics |
| 167 | + |
| 168 | +In the Pro edition, if some of the predefined schematics do not suit your project, you can disable them, and even replace them with your own custom schematics. |
| 169 | + |
| 170 | +<br> |
| 171 | + |
| 172 | +💎 **[Try the Pro edition for free](https://cyrilletuzi.gumroad.com/l/schematicspro/1million)** 💎 |
| 173 | + |
| 174 | +<br> |
| 175 | + |
| 176 | +## Other guides |
| 177 | + |
| 178 | +- [Documentation homepage](./documentation.md) |
| 179 | +- [First generation](./firstGeneration.md) |
| 180 | +- [Troubleshooting](./troubleshooting.md) |
| 181 | +- [Additional schematics 💎](./advancedSchematics.md) |
| 182 | +- [Advanced options 💎](./advancedOptions.md) |
| 183 | +- [Legacy features 💎](./legacy.md) |
| 184 | +- [Custom schematics 💎](./customSchematics.md) |
| 185 | +- [Test schematics 💎](./testing.md) |
| 186 | +- [Predefined paths 💎](./predefinedPaths.md) |
| 187 | + |
| 188 | +<br> |
0 commit comments