diff --git a/aio/content/guide/aot-compiler.md b/aio/content/guide/aot-compiler.md index bff4a9fe88..684a2f0a70 100644 --- a/aio/content/guide/aot-compiler.md +++ b/aio/content/guide/aot-compiler.md @@ -195,14 +195,15 @@ include a copy of the information that is in the `.metadata.json` file. This option tells the template compiler to report an error to the `.metadata.json` file if `"skipMetadataEmit"` is `false` . This option is `false` by default. This should only be used when `"skipMetadataEmit"` is `false` and `"skipTemplateCodeGen"` is `true`. + 这个选项告诉模板编译器如果 `"skipMetadataEmit"` 为 `false`,那就把错误信息汇报到 `.metadata.json` 中。 只有当 `"skipMetadataEmit"` 为 `false` 且 `"skipTemplateCodeGen"` 为 `true` 时才应该使用这个选项。 It is intended to validate the `.metadata.json` files emitted for bundling with an `npm` package. The validation is overly strict and can emit errors for metadata that would never produce an error when used by the template compiler. You can choose to suppress the error emitted by this option for an exported symbol by including `@dynamic` in the comment documenting the symbol. 它的设计意图是要验证为打包 `npm` 而生成的 `.metadata.json` 文件。 -这种验证非常严格,因此在使用模板编译器时可能会对那些铁定不会出错的元数据文件报告一些错误。 -你可以用 `@dynamic` 在注释中指定一些符号,来禁止对它们报告错误。 +这种验证过于严格,在使用模板编译器时甚至可能会对那些铁定不会出错的元数据文件报告一些错误。 +你可以用 `@dynamic` 在注释中指定一些要导出的符号,来禁止对它们报告错误。 It is valid for `.metadata.json` files to contain errors. The template compiler reports these errors if the metadata is used to determine the contents of an annotation. The metadata @@ -212,6 +213,12 @@ nodes to report an error if these symbols are used. If the client of a library i this until the client uses the symbol. This option allows detecting these errors during the build phase of the library and is used, for example, in producing Angular libraries themselves. +对于 `.metadata.json` 文件来说,包含错误是正常的。如果这些元数据被用来确定注解的内容,模板编译器就会报告这些错误。 +元数据收集器无法判断这些符号的设计目的是用在注解中,所以它将会自作主张,在元数据中为这些导出的符号添加错误节点。 +如果这些符号被用到了,模板编译器就会根据这些错误节点报告错误。 +如果某个库的使用者只是在注解中(而不是普通代码中)使用这些符号,模板编译器通常不会报错。 +这个选项允许在该库(比如 Angular 自身这些库)的构建和使用过程中检测这类错误。 + ### *skipTemplateCodegen* This option tells the compiler to suppress emitting `.ngfactory.js` and `.ngstyle.js` files. When set, @@ -221,14 +228,23 @@ template compiler to produce `.metadata.json` files for distribution with an `np avoiding the production of `.ngfactory.js` and `.ngstyle.js` files that cannot be distributed to `npm`. +这个选项告诉编译器忽略从 `.ngfactory.js` 和 `.ngstyle.js` 文件中发出的错误。 +如果为 `true`,它就会关闭大多数的模板编译器,并禁止汇报模板诊断信息。 +这个选项用于指示模板编译器为通过 `npm` 包分发而生成 `.metadata.json` 文件,同时避免生成无法分发到 `npm` 的 `.ngfactory.js` 和 `.ngstyle.js` 文件。 + ### *strictInjectionParameters* When set to `true`, this options tells the compiler to report an error for a parameter supplied whose injection type cannot be determined. When this value option is not provided or is `false`, constructor parameters of classes marked with `@Injectable` whose type cannot be resolved will produce a warning. +当设置为 `true` 时,该选项会告诉编译器为那些无法确定其类型的注入参数报告错误。 +当该值没有提供或未 `false` 时,那些带有 `@Injectable` 的类,如果其构造参数的类型无法解析,就会生成一个警告。 + *Note*: It is recommended to change this option explicitly to `true` as this option will default to `true` in the future. +*注意*:建议把该选项显式改为 `true`,因为将来这个选项的默认值会是 `true`。 + ### *flatModuleOutFile* When set to `true`, this option tells the template compiler to generate a flat module @@ -241,6 +257,12 @@ for symbols exported from the library index. In the generated `.ngfactory.js` fi module index is used to import symbols that includes both the public API from the library index as well as shrowded internal symbols. +当为 `true` 时,该选项告诉模板编译器生成一个指定名字的扁平模块索引和相应的扁平模块元数据。 +当要创建像 `@angular/core` 和 `@angular/common` 这样的扁平模块包时,请使用本选项。 +当使用本选项时,库的 `package.json` 文件就会引用生成的扁平模块索引,而不是库的索引文件。 +当使用本选项时,只会生成一个 `.metadata.json` 文件,其中包含从库索引中导出的符号所需的全部元数据。 +在生成的 `.ngfactory.js` 文件中,扁平模块索会用来导入包括库的公共 API 和隐藏的内部符号在内的全部符号。 + By default the `.ts` file supplied in the `files` field is assumed to be library index. If more than one `.ts` file is specified, `libraryIndex` is used to select the file to use. If more than one `.ts` file is supplied without a `libraryIndex`, an error is produced. A flat module @@ -252,6 +274,13 @@ example `"index.js"`, which produces `index.d.ts` and `index.metadata.json` fil library's `package.json`'s `module` field would be `"index.js"` and the `typings` field would be `"index.d.ts"`. +默认情况下,`files` 字段中提供的 `.ts` 文件会被当做库索引。 +如果指定了多个 `.ts` 文件,就要用 `libraryIndex` 来选择要作为库索引的文件。 +扁平模块索引会用 `flatModuleOutFile` 中给出的名字创建 `.d.ts` 和 `.js` 文件,并放在和库索引的 `.d.ts` 文件相同的位置。 +比如,如果某个库使用 `public_api.ts` 文件作为该模块的库索引,那么 `tsconfig.json` 的 `files` 字段就应该是 `["public_api.ts"]`。 +然后可以把 `flatModuleOutFile` 选项设置为 `"index.js"`,它就会生成 `index.d.ts` 和 `index.metadata.json` 文件。 +该库的 `package.json` 文件的 `module` 字段将会是 `"index.js"`,而 `typings` 字段会是 `"index.d.ts"`。 + ### *flatModuleId* This option specifies the preferred module id to use for importing a flat module. @@ -260,43 +289,66 @@ from the flat module. This is only meaningful when `flatModuleOutFile` is also supplied. Otherwise the compiler ignores this option. +该选项指定建议的模块 ID,这个 ID 用于导入扁平模块。 +从扁平模块中导入符号时,由模板编译器生成的引用将使用这个模块名称。 +它仅在同时提供了 `flatModuleOutFile` 选项时才有意义,否则,编译器将忽略此选项。 + ### *generateCodeForLibraries* This option tells the template compiler to generate factory files (`.ngfactory.js` and `.ngstyle.js`) for `.d.ts` files with a corresponding `.metadata.json` file. This option defaults to `true`. When this option is `false`, factory files are generated only for `.ts` files. +这个选项告诉模板编译器也为与 `.metadata.json` 文件对应的 `.d.ts` 文件生成工厂文件(`.ngfactory.js` 和 `.ngstyle.js`)。 +这个选项默认为 `true`。当该选项为 `false` 时,只会为 `.ts` 文件生成工厂文件。 + This option should be set to `false` when using factory summaries. +当使用工厂汇总器时,这个选项应该设置为 `false`。 + ### *fullTemplateTypeCheck* This option tells the compiler to enable the [binding expression validation](#binding-expresion-validation) phase of the template compiler which uses TypeScript to validate binding expressions. +该选项告诉编译器要为模板编译器启用[绑定表达式验证](#binding-expresion-validation)阶段,它会使用 TypeScript 来验证绑定表达式。 + This option is `false` by default. +该选项默认是 `false`。 + *Note*: It is recommended to set this to `true` as this option will default to `true` in the future. +*注意*:建议把它设置为 `true`,因为将来它会默认为 `true`。 + ### *annotateForClosureCompiler* This option tells the compiler to 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). This option defaults to `false`. +该选项告诉编译器使用 [Tsickle](https://github.com/angular/tsickle) 来为生成的 JavaScript 添加供 [Closure Compiler](https://github.com/google/closure-compiler) 使用的 [JsDoc](http://usejsdoc.org/) 注解。 +该选项默认为 `false`。 + ### *annotationsAs* Use this option to modify how the Angular specific annotations are emitted to improve tree-shaking. Non-Angular annotations and decorators are unnaffected. Default is `static fields`. -value | description +使用这个选项来修改生成 Angular 特有注解的方式,以提升摇树优化(tree-shaking)的效果。它对 Angular 自身之外的注解和装饰器无效。 +默认值是 `static fields`。 + +value | description说明 ----------------|------------------------------------------------------------- -`decorators` | Leave the Decorators in-place. This makes compilation faster. TypeScript will emit calls to the __decorate helper. Use `--emitDecoratorMetadata` for runtime reflection. However, the resulting code will not properly tree-shake. -`static fields` | Replace decorators with a static field in the class. Allows advanced tree-shakers like [Closure Compiler](https://github.com/google/closure-compiler) to remove unused classes. +`decorators` | Leave the Decorators in-place. This makes compilation faster. TypeScript will emit calls to the `__decorate` helper. Use `--emitDecoratorMetadata` for runtime reflection. However, the resulting code will not properly tree-shake. 原地保留装饰器。这会让编译过程更快。TypeScript 将会生成对 `__decorate` 助手函数的调用。使用 `--emitDecoratorMetadata` 进行运行时反射。不过,生成的代码将无法正常进行摇树优化。 +`static fields` | Replace decorators with a static field in the class. Allows advanced tree-shakers like [Closure Compiler](https://github.com/google/closure-compiler) to remove unused classes.使用类的静态字段代替装饰器。它允许像 [Closure Compiler](https://github.com/google/closure-compiler) 这样的高级摇树优化器移除未使用的类。 ### *trace* This tells the compiler to print extra information while compiling templates. +它告诉编译器在编译模板时打印额外的信息。 + ### *enableLegacyTemplate* The use of `