You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 0035ccf
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: aio/content/guide/angular-compiler-options.md
+41-36Lines changed: 41 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Angular compiler options
2
2
3
-
When you use [AOT compilation](guide/aot-compiler), you can control how your application is compiled by specifying *template* compiler options in the [TypeScript configuration file](guide/typescript-configuration).
3
+
When you use [ahead-of-time compilation (AOT)](guide/aot-compiler), you can control how your application is compiled by specifying *template* compiler options in the [TypeScript configuration file](guide/typescript-configuration).
4
4
5
5
The template options object, `angularCompilerOptions`, is a sibling to the `compilerOptions` object that supplies standard options to the TypeScript compiler.
6
6
@@ -28,7 +28,7 @@ The following options are available for configuring the AOT template compiler.
28
28
29
29
### `allowEmptyCodegenFiles`
30
30
31
-
When `true`, generate all possible files even if they are empty.
31
+
When `true`, create all possible files even if they are empty.
32
32
Default is `false`.
33
33
Used by the Bazel build rules to simplify how Bazel rules track file dependencies.
34
34
Do not use this option outside of the Bazel rules.
@@ -37,7 +37,7 @@ Do not use this option outside of the Bazel rules.
37
37
38
38
Modifies how Angular-specific annotations are emitted to improve tree-shaking.
39
39
Non-Angular annotations are not affected.
40
-
One of `static fields`\(the default\) or `decorators`.
40
+
One of `static fields`or `decorators`. The default value is `static fields`.
41
41
42
42
* By default, the compiler replaces decorators with a static field in the class, which allows advanced tree-shakers like [Closure compiler](https://github.com/google/closure-compiler) to remove unused classes
43
43
* The `decorators` value leaves the decorators in place, which makes compilation faster.
@@ -53,9 +53,13 @@ One of `static fields` \(the default\) or `decorators`.
53
53
54
54
### `annotateForClosureCompiler`
55
55
56
+
<!-- vale Angular.Angular_Spelling = NO -->
57
+
56
58
When `true`, use [Tsickle](https://github.com/angular/tsickle) to annotate the emitted JavaScript with [JSDoc](https://jsdoc.app) comments needed by the [Closure Compiler](https://github.com/google/closure-compiler).
57
59
Default is `false`.
58
60
61
+
<!-- vale Angular.Angular_Spelling = YES -->
62
+
59
63
### `compilationMode`
60
64
61
65
Specifies the compilation mode to use.
@@ -70,29 +74,29 @@ The default value is `'full'`.
70
74
71
75
### `disableExpressionLowering`
72
76
73
-
When `true`\(the default\), transforms code that is or could be used in an annotation, to allow it to be imported from template factory modules.
77
+
When `true`, the default, transforms code that is or could be used in an annotation, to allow it to be imported from template factory modules.
74
78
See [metadata rewriting](guide/aot-compiler#metadata-rewriting) for more information.
75
79
76
80
When `false`, disables this rewriting, requiring the rewriting to be done manually.
77
81
78
82
### `disableTypeScriptVersionCheck`
79
83
80
-
When `true`, the compiler does not check the TypeScript version and does not report an error when an unsupported version of TypeScript is used.
84
+
When `true`, the compiler does not look at the TypeScript version and does not report an error when an unsupported version of TypeScript is used.
81
85
Not recommended, as unsupported versions of TypeScript might have undefined behavior.
82
86
Default is `false`.
83
87
84
88
### `enableI18nLegacyMessageIdFormat`
85
89
86
-
Instructs the Angular template compiler to generate legacy ids for messages that are tagged in templates by the `i18n` attribute.
90
+
Instructs the Angular template compiler to create legacy ids for messages that are tagged in templates by the `i18n` attribute.
87
91
See [Mark text for translations][AioGuideI18nCommonPrepareMarkTextInComponentTemplate] for more information about marking messages for localization.
88
92
89
-
Set this option to `false` unless your project relies upon translations that were previously generated using legacy IDs.
93
+
Set this option to `false` unless your project relies upon translations that were created earlier using legacy IDs.
90
94
Default is `true`.
91
95
92
-
The pre-Ivy message extraction tooling generated a variety of legacy formats for extracted message IDs.
93
-
These message formats have a number of issues, such as whitespace handling and reliance upon information inside the original HTML of a template.
96
+
The pre-Ivy message extraction tooling created a variety of legacy formats for extracted message IDs.
97
+
These message formats have some issues, such as whitespace handling and reliance upon information inside the original HTML of a template.
94
98
95
-
The new message format is more resilient to whitespace changes, is the same across all translation file formats, and can be generated directly from calls to `$localize`.
99
+
The new message format is more resilient to whitespace changes, is the same across all translation file formats, and can be created directly from calls to `$localize`.
96
100
This allows `$localize` messages in application code to use the same ID as identical `i18n` messages in component templates.
97
101
98
102
### `enableResourceInlining`
@@ -101,30 +105,30 @@ When `true`, replaces the `templateUrl` and `styleUrls` properties in all `@Comp
101
105
102
106
When enabled, the `.js` output of `ngc` does not include any lazy-loaded template or style URLs.
103
107
104
-
For library projects generated with the Angular CLI, the development configuration default is `true`.
108
+
For library projects created with the Angular CLI, the development configuration default is `true`.
105
109
106
110
<aid="enablelegacytemplate"></a>
107
111
108
112
### `enableLegacyTemplate`
109
113
110
-
When `true`, enables use of the `<template>` element, which was deprecated in Angular 4.0, in favor of `<ng-template>`\(to avoid colliding with the DOM's element of the same name\).
114
+
When `true`, enables the deprecated `<template>` elementin place of `<ng-template>`.
111
115
Default is `false`.
112
116
Might be required by some third-party Angular libraries.
113
117
114
118
### `flatModuleId`
115
119
116
120
The module ID to use for importing a flat module \(when `flatModuleOutFile` is `true`\).
117
-
References generated by the template compiler use this module name when importing symbols from the flat module.
121
+
References created by the template compiler use this module name when importing symbols from the flat module.
118
122
Ignored if `flatModuleOutFile` is `false`.
119
123
120
124
### `flatModuleOutFile`
121
125
122
126
When `true`, generates a flat module index of the given filename and the corresponding flat module metadata.
123
127
Use to create flat modules that are packaged similarly to `@angular/core` and `@angular/common`.
124
-
When this option is used, the `package.json` for the library should refer to the generated flat module index instead of the library index file.
128
+
When this option is used, the `package.json` for the library should refer to the created flat module index instead of the library index file.
125
129
126
130
Produces only one `.metadata.json` file, which contains all the metadata necessary for symbols exported from the library index.
127
-
In the generated`.ngfactory.js` files, the flat module index is used to import symbols that include both the public API from the library index as well as shrouded internal symbols.
131
+
In the created`.ngfactory.js` files, the flat module index is used to import symbols. Symbols that include both the public API from the library index as well as shrouded internal symbols.
128
132
129
133
By default the `.ts` file supplied in the `files` field is assumed to be the library index.
130
134
If more than one `.ts` file is specified, `libraryIndex` is used to select the file to use.
@@ -133,15 +137,15 @@ If more than one `.ts` file is supplied without a `libraryIndex`, an error is pr
133
137
A flat module index `.d.ts` and `.js` is created with the given `flatModuleOutFile` name in the same location as the library index `.d.ts` file.
134
138
135
139
For example, if a library uses the `public_api.ts` file as the library index of the module, the `tsconfig.json``files` field would be `["public_api.ts"]`.
136
-
The `flatModuleOutFile` option could then be set to \(for example\)`"index.js"`, which produces `index.d.ts` and `index.metadata.json` files.
140
+
The `flatModuleOutFile` option could then be set, for example, to`"index.js"`, which produces `index.d.ts` and `index.metadata.json` files.
137
141
The `module` field of the library's `package.json` would be `"index.js"` and the `typings` field would be `"index.d.ts"`.
138
142
139
143
### `fullTemplateTypeCheck`
140
144
141
-
When `true`\(recommended\), enables the [binding expression validation](guide/aot-compiler#binding-expression-validation) phase of the template compiler, which uses TypeScript to validate binding expressions.
145
+
When `true`, the recommended value, enables the [binding expression validation](guide/aot-compiler#binding-expression-validation) phase of the template compiler. This phase uses TypeScript to verify binding expressions.
142
146
For more information, see [Template type checking](guide/template-typecheck).
143
147
144
-
Default is `false`, but when you use the Angular CLI command `ng new --strict`, it is set to `true` in the generated project's configuration.
148
+
Default is `false`, but when you use the Angular CLI command `ng new --strict`, it is set to `true` in the new project's configuration.
145
149
146
150
<divclass="alert is-important">
147
151
@@ -151,14 +155,14 @@ The `fullTemplateTypeCheck` option has been deprecated in Angular 13 in favor of
151
155
152
156
### `generateCodeForLibraries`
153
157
154
-
When `true`\(the default\), generates factory files \(`.ngfactory.js` and `.ngstyle.js`\) for `.d.ts` files with a corresponding `.metadata.json` file.
158
+
When `true`, creates factory files \(`.ngfactory.js` and `.ngstyle.js`\) for `.d.ts` files with a corresponding `.metadata.json` file. The default value is `true`.
155
159
156
-
When `false`, factory files are generated only for `.ts` files.
160
+
When `false`, factory files are created only for `.ts` files.
157
161
Do this when using factory summaries.
158
162
159
163
### `preserveWhitespaces`
160
164
161
-
When `false`\(the default\), removes blank text nodes from compiled templates, which results in smaller emitted template factory modules.
165
+
When `false`, the default, removes blank text nodes from compiled templates, which results in smaller emitted template factory modules.
162
166
Set to `true` to preserve blank text nodes.
163
167
164
168
### `skipMetadataEmit`
@@ -167,58 +171,59 @@ When `true`, does not produce `.metadata.json` files.
167
171
Default is `false`.
168
172
169
173
The `.metadata.json` files contain information needed by the template compiler from a `.ts` file that is not included in the `.d.ts` file produced by the TypeScript compiler.
170
-
This information includes, for example, the content of annotations\(such as a component's template\), which TypeScript emits to the `.js` file but not to the `.d.ts` file.
174
+
This information includes, for example, the content of annotations, such as a component's template, which TypeScript emits to the `.js` file but not to the `.d.ts` file.
171
175
172
176
You can set to `true` when using factory summaries, because the factory summaries include a copy of the information that is in the `.metadata.json` file.
173
177
174
178
Set to `true` if you are using TypeScript's `--outFile` option, because the metadata files are not valid for this style of TypeScript output.
175
-
However, the Angular community does not recommend using `--outFile` with Angular.
179
+
The Angular community does not recommend using `--outFile` with Angular.
176
180
Use a bundler, such as [webpack](https://webpack.js.org), instead.
177
181
178
182
### `skipTemplateCodegen`
179
183
180
184
When `true`, does not emit `.ngfactory.js` and `.ngstyle.js` files.
181
185
This turns off most of the template compiler and disables the reporting of template diagnostics.
182
186
183
-
Can be used to instruct the template compiler to produce `.metadata.json` files for distribution with an `npm` package while avoiding the production of `.ngfactory.js` and `.ngstyle.js` files that cannot be distributed to `npm`.
187
+
Can be used to instruct the template compiler to produce `.metadata.json` files for distribution with an `npm` package. This avoids the production of `.ngfactory.js` and `.ngstyle.js` files that cannot be distributed to `npm`.
184
188
185
-
For library projects generated with the Angular CLI, the development configuration default is `true`.
189
+
For library projects created with the Angular CLI, the development configuration default is `true`.
186
190
187
191
### `strictMetadataEmit`
188
192
189
193
When `true`, reports an error to the `.metadata.json` file if `"skipMetadataEmit"` is `false`.
190
194
Default is `false`.
191
195
Use only when `"skipMetadataEmit"` is `false` and `"skipTemplateCodegen"` is `true`.
192
196
193
-
This option is intended to validate the `.metadata.json` files emitted for bundling with an `npm` package.
197
+
This option is intended to verify the `.metadata.json` files emitted for bundling with an `npm` package.
194
198
The validation is strict and can emit errors for metadata that would never produce an error when used by the template compiler.
195
199
You can choose to suppress the error emitted by this option for an exported symbol by including `@dynamic` in the comment documenting the symbol.
196
200
197
201
It is valid for `.metadata.json` files to contain errors.
198
202
The template compiler reports these errors if the metadata is used to determine the contents of an annotation.
199
-
The metadata collector cannot predict the symbols that are designed for use in an annotation, so it preemptively includes error nodes in the metadata for the exported symbols.
203
+
The metadata collector cannot predict the symbols that are designed for use in an annotation. It preemptively includes error nodes in the metadata for the exported symbols.
200
204
The template compiler can then use the error nodes to report an error if these symbols are used.
201
205
202
-
If the client of a library intends to use a symbol in an annotation, the template compiler does not normally report this until the client uses the symbol.
206
+
If the client of a library intends to use a symbol in an annotation, the template compiler does not normally report this. It gets reported after the client actually uses the symbol.
203
207
This option allows detection of these errors during the build phase of the library and is used, for example, in producing Angular libraries themselves.
204
208
205
-
For library projects generated with the Angular CLI, the development configuration default is `true`.
209
+
For library projects created with the Angular CLI, the development configuration default is `true`.
206
210
207
211
### `strictInjectionParameters`
208
212
209
-
When `true`\(recommended\), reports an error for a supplied parameter whose injection type cannot be determined.
210
-
When `false`\(currently the default\), constructor parameters of classes marked with `@Injectable` whose type cannot be resolved produce a warning.
213
+
When `true`, reports an error for a supplied parameter whose injection type cannot be determined.
214
+
When `false`, constructor parameters of classes marked with `@Injectable` whose type cannot be resolved produce a warning.
215
+
The recommended value is `true`, but the default value is `false`.
211
216
212
-
When you use the Angular CLI command `ng new --strict`, it is set to `true` in the generated project's configuration.
217
+
When you use the Angular CLI command `ng new --strict`, it is set to `true` in the created project's configuration.
213
218
214
219
### `strictTemplates`
215
220
216
221
When `true`, enables [strict template type checking](guide/template-typecheck#strict-mode).
217
222
218
-
Additional strictness flags allow you to enable and disable specific types of strict template type checking.
223
+
The strictness flags that this open enables allow you to turn on and off specific types of strict template type checking.
219
224
See [troubleshooting template errors](guide/template-typecheck#troubleshooting-template-errors).
220
225
221
-
When you use the Angular CLI command `ng new --strict`, it is set to `true` in the generated project's configuration.
226
+
When you use the Angular CLI command `ng new --strict`, it is set to `true` in the new project's configuration.
222
227
223
228
### `trace`
224
229
@@ -229,12 +234,12 @@ Default is `false`.
229
234
230
235
## Command line options
231
236
232
-
While most of the time you interact with the Angular Compiler indirectly using Angular CLI, when debugging certain issues, you might find it useful to invoke the Angular Compiler directly.
237
+
Most of the time you interact with the Angular Compiler indirectly using Angular CLI. When debugging certain issues, you might find it useful to invoke the Angular Compiler directly.
233
238
You can use the `ngc` command provided by the `@angular/compiler-cli` npm package to call the compiler from the command line.
234
239
235
240
The `ngc` command is just a wrapper around TypeScript's `tsc` compiler command and is primarily configured via the `tsconfig.json` configuration options documented in [the previous sections](#angular-compiler-options).
236
241
237
-
In addition to the configuration file, you can also use [`tsc` command line options](https://www.typescriptlang.org/docs/handbook/compiler-options.html) to configure `ngc`.
242
+
Besides the configuration file, you can also use [`tsc` command line options](https://www.typescriptlang.org/docs/handbook/compiler-options.html) to configure `ngc`.
0 commit comments