# Angular compiler options # Angular 编译器选项 When you use [AOT compilation](guide/aot-compiler), you can control how your application is compiled by specifying *template* compiler options in the `tsconfig.json` [TypeScript configuration file](guide/typescript-configuration). 使用 [AoT 编译](guide/aot-compiler) 时,可以通过在 `tsconfig.json` [TypeScript 配置文件中](guide/typescript-configuration)指定*模板*编译器选项来控制如何编译应用程序。 The template options object, `angularCompilerOptions`, is a sibling to the `compilerOptions` object that supplies standard options to the TypeScript compiler. 模板选项对象 `angularCompilerOptions` 和为 TypeScript 编译器提供标准选项的 `compilerOptions` 对象是兄弟。 ```json { "compilerOptions": { "experimentalDecorators": true, ... }, "angularCompilerOptions": { "fullTemplateTypeCheck": true, "preserveWhitespaces": true, ... } } ``` {@a tsconfig-extends} ## Configuration inheritance with extends ## 用 `extends` 语法配置继承方式 Like the TypeScript compiler, The Angular AOT compiler also supports `extends` in the `angularCompilerOptions` section of the TypeScript configuration file, `tsconfig.json`. The `extends` property is at the top level, parallel to `compilerOptions` and `angularCompilerOptions`. 像 TypeScript 编译器一样,Angular 的 AOT 编译器也支持对 TypeScript 配置文件 `tsconfig.json` 的 `angularCompilerOptions` 进行 `extends`。`extends` 属性位于顶层,和 `compilerOptions` 和 `angularCompilerOptions` 平级。 A TypeScript configuration can inherit settings from another file using the `extends` property. The configuration options from the base file are loaded first, then overridden by those in the inheriting `tsconfig` file. 使用 `extends` 属性,TypeScript 配置可以从另一个文件中继承设置。首先从基础文件中加载配置项,然后被继承它的 `tsconfig` 文件中的配置项覆写。 For example: 比如: ```json { "extends": "../tsconfig.base.json", "compilerOptions": { "experimentalDecorators": true, ... }, "angularCompilerOptions": { "fullTemplateTypeCheck": true, "preserveWhitespaces": true, ... } } ``` For more information, see the [TypeScript Handbook](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html). 欲知详情,请参见 [TypeScript 手册](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) 。 ## Template options ## 模板选项 The following options are available for configuring the AOT template compiler. 以下选项可用于配置 AoT 模板编译器。 ### `allowEmptyCodegenFiles` When `true`, generate all possible files even if they are empty. Default is `false`. Used by the Bazel build rules to simplify how Bazel rules track file dependencies. Do not use this option outside of the Bazel rules. 如果为`true`,则生成所有可能的文件 —— 即使它们为空。默认值为 `false`。 Bazel 的构建规则使用它来简化 Bazel 规则跟踪文件依赖性的方式。不要在 Bazel 规则之外使用此选项。 ### `annotationsAs` Modifies how Angular-specific annotations are emitted to improve tree-shaking. Non-Angular annotations are not affected. One of `static fields` (the default) or `decorators`. 修改 Angular 专有注解的生成方式,以改善摇树优化。非 Angular 注解不受影响。可选值为 `static fields`(默认值)或`decorators` 。 * 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. 默认情况下,编译器会用类中的静态字段替换装饰器,这允许像 [Closure 编译器](https://github.com/google/closure-compiler)这样的高级摇树器删除未使用的类。 * The `decorators` value leaves the decorators in place, which makes compilation faster. TypeScript emits calls to the`__decorate` helper. Use `--emitDecoratorMetadata` for runtime reflection (but note that the resulting code will not properly tree-shake. `decorators` 值会将装饰器保留在原处,这将使编译速度更快。TypeScript 会发出对 `__decorate` 辅助程序的调用。使用 `--emitDecoratorMetadata` 进行运行时反射(但请注意,生成的代码将无法正确摇树)。 ### `annotateForClosureCompiler` When `true`, use [Tsickle](https://github.com/angular/tsickle) to annotate the emitted JavaScript with [JSDoc](http://usejsdoc.org/) comments needed by the [Closure Compiler](https://github.com/google/closure-compiler). Default is `false`. 如果为 `true`,则使用 [Tsickle](https://github.com/angular/tsickle) 来用 [JSDoc](http://usejsdoc.org/) 对生成的 JavaScript 代码进行注解,这些注释是供 [Closure 编译器](https://github.com/google/closure-compiler) 使用的。默认值为`false` 。 ### `disableExpressionLowering` 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. See [metadata rewriting](guide/aot-compiler#metadata-rewriting) for more information. 如果为`true`(默认值),则转换在注解中使用或允许使用的代码,以允许从模板的工厂模块导入代码。欲知详情,请参见[元数据重写](guide/aot-compiler#metadata-rewriting) 。 When `false`, disables this rewriting, requiring the rewriting to be done manually. 如果为`false`,则禁用此重写,你必须手动进行重写。 ### `disableTypeScriptVersionCheck` When `true`, the compiler does not check the TypeScript version and does not report an error when an unsupported version of TypeScript is used. Not recommended, as unsupported versions of TypeScript might have undefined behavior. Default is `false`. 如果为 `true`,则在使用不受支持的 TypeScript 版本时,编译器不会检查 TypeScript 版本,并且不会报错。不建议使用,因为不受支持的 TypeScript 版本可能具有未定义的行为。默认值为 `false` 。 ### `enableIvy` Enables the [Ivy](guide/ivy) compilation and rendering pipeline. Default is `true`, as of version 9. In version 9, you can [opt out of Ivy](guide/ivy#opting-out-of-angular-ivy) to continue using the previous compiler, View Engine. 启用 [Ivy](guide/ivy) 编译和渲染管道。从版本 9 开始,默认值为 `true` 。在版本 9 中,您可以[选择不用 Ivy](guide/ivy#opting-out-of-angular-ivy) 而是继续使用以前的编译器 View Engine。 For library projects generated with the CLI, the `prod` configuration default is `false` in version 9. 对于使用 CLI 生成的*库*项目,`prod` 配置默认在版本9中为 `false`。 ### `enableResourceInlining` When `true`, replaces the `templateUrl` and `styleUrls` property in all `@Component` decorators with inlined contents in `template` and `styles` properties. 当为 `true` 时,将所有 `@Component` 装饰器中的 `templateUrl` 和 `styleUrls` 属性替换为 `template` 和 `styles` 属性中的内联内容。 When enabled, the `.js` output of `ngc` does not include any lazy-loaded template or style URLs. 启用后,`ngc` 的 `.js` 输出不会包含任何延迟加载的模板或样式 URL。 For library projects generated with the CLI, the dev configuration default is `true`. 对于使用 CLI 生成的库项目,dev 配置下默认为 `true` 。 {@a enablelegacytemplate} ### `enableLegacyTemplate` When `true`, enables use of the `