angular-cn/public/docs/ts/latest/guide/npm-packages.jade

393 lines
23 KiB
Plaintext
Raw Normal View History

include ../_util-fns
:marked
Angular applications and Angular itself depend upon features and functionality provided by a variety of third-party packages.
2016-04-27 14:28:22 -04:00
These packages are maintained and installed with the Node Package Manager (<a href="https://docs.npmjs.com/" target="_blank">npm</a>).
2016-05-26 08:50:46 -04:00
Angular应用程序以及Angular本身都依赖于很多第三方包(包括Angular自己)提供的特性和功能。
2016-05-26 08:50:46 -04:00
这些包由Node包管理器(<a href="https://docs.npmjs.com/" target="_blank">npm</a>)负责安装和维护。
.l-sub-section
:marked
Node.js and npm are essential to Angular development.
2016-05-26 08:50:46 -04:00
Node.js和npm是做Angular 2开发的基础。
<a href="https://docs.npmjs.com/getting-started/installing-node" target="_blank" title="Installing Node.js and updating npm">
Get them now</a> if they're not already installed on your machine.
2016-05-26 08:50:46 -04:00
2016-06-05 17:48:50 -04:00
如果你的电脑上还没有装过,请<a href="https://docs.npmjs.com/getting-started/installing-node" target="_blank" title="Installing Node.js and updating npm">立即获取它</a>
**Verify that you are running node `v4.x.x` or higher and npm `3.x.x` or higher**
by running the commands `node -v` and `npm -v` in a terminal/console window.
Older versions produce errors.
2016-05-26 08:50:46 -04:00
通过在终端/控制台窗口中运行`node -v`和`npm -v`命令,来**验证下你是否正在使用node `v5.x.x`和npm `3.x.x`**。
过老的版本有可能出现问题。
We recommend [nvm](https://github.com/creationix/nvm) for managing multiple versions of node and npm. You may need [nvm](https://github.com/creationix/nvm) if you already have projects running on your machine that use other versions of node and npm.
2016-05-26 08:50:46 -04:00
Merge remote-tracking branch 'origin/master' # Conflicts: # README.md # public/_includes/_scripts-include.jade # public/docs/_examples/homepage-hello-world/ts/index.1.html # public/docs/_examples/homepage-tabs/ts/index.1.html # public/docs/_examples/homepage-todo/ts/index.1.html # public/docs/_examples/systemjs.config.plunker.build.js # public/docs/_examples/systemjs.config.plunker.js # public/docs/js/latest/cookbook/ts-to-js.jade # public/docs/ts/latest/_data.json # public/docs/ts/latest/cookbook/component-communication.jade # public/docs/ts/latest/cookbook/component-relative-paths.jade # public/docs/ts/latest/glossary.jade # public/docs/ts/latest/guide/_data.json # public/docs/ts/latest/guide/architecture.jade # public/docs/ts/latest/guide/attribute-directives.jade # public/docs/ts/latest/guide/dependency-injection.jade # public/docs/ts/latest/guide/index.jade # public/docs/ts/latest/guide/lifecycle-hooks.jade # public/docs/ts/latest/guide/ngmodule.jade # public/docs/ts/latest/guide/npm-packages.jade # public/docs/ts/latest/guide/security.jade # public/docs/ts/latest/guide/server-communication.jade # public/docs/ts/latest/guide/template-syntax.jade # public/docs/ts/latest/guide/typescript-configuration.jade # public/docs/ts/latest/index.jade # public/docs/ts/latest/quickstart.jade # public/docs/ts/latest/tutorial/_data.json # public/docs/ts/latest/tutorial/toh-pt6.jade # public/features.jade # public/resources/js/directives/live-example.js # tools/plunker-builder/indexHtmlTranslator.js
2016-09-08 05:20:01 -04:00
我们建议使用[nvm](https://github.com/creationix/nvm)来管理node和npm的多个版本。如果你机器上已经有某些项目运行了node和npm的其它版本你就会需要[nvm](https://github.com/creationix/nvm)了。
:marked
2016-04-27 14:28:22 -04:00
We recommend a comprehensive starter-set of packages as specified in the `dependencies` and `devDependencies`
sections of the QuickStart
<a href="https://docs.npmjs.com/files/package.json" target="_blank">package.json</a> file:
2016-05-26 08:50:46 -04:00
我们在“快速起步”一章中<a href="https://docs.npmjs.com/files/package.json" target="_blank">package.json</a>文件的
2016-06-05 17:48:50 -04:00
`dependencies`和`devDependencies`区中指定了一组适用于新手的综合依赖包。
+makeJson('quickstart/ts/package.1.json',{ paths: 'dependencies, devDependencies'}, 'package.json (dependencies)')(format=".")
:marked
You can use other packages but we recommend *this particular set* to start with because (a) they work well together and
(b) they include everything you'll need to build and run the sample applications in this series.
2016-05-26 08:50:46 -04:00
Merge remote-tracking branch 'origin/master' # Conflicts: # README.md # public/_includes/_scripts-include.jade # public/docs/_examples/homepage-hello-world/ts/index.1.html # public/docs/_examples/homepage-tabs/ts/index.1.html # public/docs/_examples/homepage-todo/ts/index.1.html # public/docs/_examples/systemjs.config.plunker.build.js # public/docs/_examples/systemjs.config.plunker.js # public/docs/js/latest/cookbook/ts-to-js.jade # public/docs/ts/latest/_data.json # public/docs/ts/latest/cookbook/component-communication.jade # public/docs/ts/latest/cookbook/component-relative-paths.jade # public/docs/ts/latest/glossary.jade # public/docs/ts/latest/guide/_data.json # public/docs/ts/latest/guide/architecture.jade # public/docs/ts/latest/guide/attribute-directives.jade # public/docs/ts/latest/guide/dependency-injection.jade # public/docs/ts/latest/guide/index.jade # public/docs/ts/latest/guide/lifecycle-hooks.jade # public/docs/ts/latest/guide/ngmodule.jade # public/docs/ts/latest/guide/npm-packages.jade # public/docs/ts/latest/guide/security.jade # public/docs/ts/latest/guide/server-communication.jade # public/docs/ts/latest/guide/template-syntax.jade # public/docs/ts/latest/guide/typescript-configuration.jade # public/docs/ts/latest/index.jade # public/docs/ts/latest/quickstart.jade # public/docs/ts/latest/tutorial/_data.json # public/docs/ts/latest/tutorial/toh-pt6.jade # public/features.jade # public/resources/js/directives/live-example.js # tools/plunker-builder/indexHtmlTranslator.js
2016-09-08 05:20:01 -04:00
你当然可以使用其它包,不过我们建议你先使用*这一组*,因为:(a) 我们知道它们可以很好的协同工作;(b) 它们包含了我们在个系列文档中构建和运行范例应用时所需的一切。
2016-04-27 14:28:22 -04:00
.l-sub-section
:marked
Note: A cookbook or guide page may require an additional library such as *jQuery*.
2016-05-26 08:50:46 -04:00
Merge remote-tracking branch 'origin/master' # Conflicts: # README.md # public/_includes/_scripts-include.jade # public/docs/_examples/homepage-hello-world/ts/index.1.html # public/docs/_examples/homepage-tabs/ts/index.1.html # public/docs/_examples/homepage-todo/ts/index.1.html # public/docs/_examples/systemjs.config.plunker.build.js # public/docs/_examples/systemjs.config.plunker.js # public/docs/js/latest/cookbook/ts-to-js.jade # public/docs/ts/latest/_data.json # public/docs/ts/latest/cookbook/component-communication.jade # public/docs/ts/latest/cookbook/component-relative-paths.jade # public/docs/ts/latest/glossary.jade # public/docs/ts/latest/guide/_data.json # public/docs/ts/latest/guide/architecture.jade # public/docs/ts/latest/guide/attribute-directives.jade # public/docs/ts/latest/guide/dependency-injection.jade # public/docs/ts/latest/guide/index.jade # public/docs/ts/latest/guide/lifecycle-hooks.jade # public/docs/ts/latest/guide/ngmodule.jade # public/docs/ts/latest/guide/npm-packages.jade # public/docs/ts/latest/guide/security.jade # public/docs/ts/latest/guide/server-communication.jade # public/docs/ts/latest/guide/template-syntax.jade # public/docs/ts/latest/guide/typescript-configuration.jade # public/docs/ts/latest/index.jade # public/docs/ts/latest/quickstart.jade # public/docs/ts/latest/tutorial/_data.json # public/docs/ts/latest/tutorial/toh-pt6.jade # public/features.jade # public/resources/js/directives/live-example.js # tools/plunker-builder/indexHtmlTranslator.js
2016-09-08 05:20:01 -04:00
注意:烹饪宝典或开发指南中的页面可能需要额外的库,比如*jQuery*。
2016-04-27 14:28:22 -04:00
:marked
You'll install more than you need for QuickStart.
No worries!
You only serve to the client those packages that the application actually requests.
2016-06-05 17:48:50 -04:00
它们远远超过了我们将在“快速起步”中所需要用到的。
2016-05-26 08:50:46 -04:00
实际上,它比我们在大多数应用中需要的还多。
安装的包比我们实际需要的包多,其实并没有什么坏处。
我们最终只会往客户端发送程序中实际用到的那些包。
This page explains what each package does. You can make substitutions later to suit your tastes and experience.
Merge remote-tracking branch 'origin/master' # Conflicts: # README.md # public/_includes/_scripts-include.jade # public/docs/_examples/homepage-hello-world/ts/index.1.html # public/docs/_examples/homepage-tabs/ts/index.1.html # public/docs/_examples/homepage-todo/ts/index.1.html # public/docs/_examples/systemjs.config.plunker.build.js # public/docs/_examples/systemjs.config.plunker.js # public/docs/js/latest/cookbook/ts-to-js.jade # public/docs/ts/latest/_data.json # public/docs/ts/latest/cookbook/component-communication.jade # public/docs/ts/latest/cookbook/component-relative-paths.jade # public/docs/ts/latest/glossary.jade # public/docs/ts/latest/guide/_data.json # public/docs/ts/latest/guide/architecture.jade # public/docs/ts/latest/guide/attribute-directives.jade # public/docs/ts/latest/guide/dependency-injection.jade # public/docs/ts/latest/guide/index.jade # public/docs/ts/latest/guide/lifecycle-hooks.jade # public/docs/ts/latest/guide/ngmodule.jade # public/docs/ts/latest/guide/npm-packages.jade # public/docs/ts/latest/guide/security.jade # public/docs/ts/latest/guide/server-communication.jade # public/docs/ts/latest/guide/template-syntax.jade # public/docs/ts/latest/guide/typescript-configuration.jade # public/docs/ts/latest/index.jade # public/docs/ts/latest/quickstart.jade # public/docs/ts/latest/tutorial/_data.json # public/docs/ts/latest/tutorial/toh-pt6.jade # public/features.jade # public/resources/js/directives/live-example.js # tools/plunker-builder/indexHtmlTranslator.js
2016-09-08 05:20:01 -04:00
本页面会解释每一个包是干什么的,以后你就可以根据自己的喜好和经验,随意替换它们了。
2016-05-26 08:50:46 -04:00
.l-main-section
:marked
## *dependencies* and *devDependencies*
2016-05-26 08:50:46 -04:00
## *dependencies*和*devDependencies*
The `package.json` includes two sets of packages,
[dependencies](#dependencies) and [devDependencies](#dev-dependencies).
Merge remote-tracking branch 'origin/master' # Conflicts: # README.md # public/_includes/_scripts-include.jade # public/docs/_examples/homepage-hello-world/ts/index.1.html # public/docs/_examples/homepage-tabs/ts/index.1.html # public/docs/_examples/homepage-todo/ts/index.1.html # public/docs/_examples/systemjs.config.plunker.build.js # public/docs/_examples/systemjs.config.plunker.js # public/docs/js/latest/cookbook/ts-to-js.jade # public/docs/ts/latest/_data.json # public/docs/ts/latest/cookbook/component-communication.jade # public/docs/ts/latest/cookbook/component-relative-paths.jade # public/docs/ts/latest/glossary.jade # public/docs/ts/latest/guide/_data.json # public/docs/ts/latest/guide/architecture.jade # public/docs/ts/latest/guide/attribute-directives.jade # public/docs/ts/latest/guide/dependency-injection.jade # public/docs/ts/latest/guide/index.jade # public/docs/ts/latest/guide/lifecycle-hooks.jade # public/docs/ts/latest/guide/ngmodule.jade # public/docs/ts/latest/guide/npm-packages.jade # public/docs/ts/latest/guide/security.jade # public/docs/ts/latest/guide/server-communication.jade # public/docs/ts/latest/guide/template-syntax.jade # public/docs/ts/latest/guide/typescript-configuration.jade # public/docs/ts/latest/index.jade # public/docs/ts/latest/quickstart.jade # public/docs/ts/latest/tutorial/_data.json # public/docs/ts/latest/tutorial/toh-pt6.jade # public/features.jade # public/resources/js/directives/live-example.js # tools/plunker-builder/indexHtmlTranslator.js
2016-09-08 05:20:01 -04:00
`package.json`包含两组包:[dependencies](#dependencies)和[devDependencies](#dev-dependencies)。
2016-05-26 08:50:46 -04:00
The *dependencies* are essential to *running* the application.
The *devDependencies* are only necessary to *develop* the application.
You can exclude them from production installations by adding `--production` to the install command, as follows:
Merge remote-tracking branch 'origin/master' # Conflicts: # README.md # public/_includes/_scripts-include.jade # public/docs/_examples/homepage-hello-world/ts/index.1.html # public/docs/_examples/homepage-tabs/ts/index.1.html # public/docs/_examples/homepage-todo/ts/index.1.html # public/docs/_examples/systemjs.config.plunker.build.js # public/docs/_examples/systemjs.config.plunker.js # public/docs/js/latest/cookbook/ts-to-js.jade # public/docs/ts/latest/_data.json # public/docs/ts/latest/cookbook/component-communication.jade # public/docs/ts/latest/cookbook/component-relative-paths.jade # public/docs/ts/latest/glossary.jade # public/docs/ts/latest/guide/_data.json # public/docs/ts/latest/guide/architecture.jade # public/docs/ts/latest/guide/attribute-directives.jade # public/docs/ts/latest/guide/dependency-injection.jade # public/docs/ts/latest/guide/index.jade # public/docs/ts/latest/guide/lifecycle-hooks.jade # public/docs/ts/latest/guide/ngmodule.jade # public/docs/ts/latest/guide/npm-packages.jade # public/docs/ts/latest/guide/security.jade # public/docs/ts/latest/guide/server-communication.jade # public/docs/ts/latest/guide/template-syntax.jade # public/docs/ts/latest/guide/typescript-configuration.jade # public/docs/ts/latest/index.jade # public/docs/ts/latest/quickstart.jade # public/docs/ts/latest/tutorial/_data.json # public/docs/ts/latest/tutorial/toh-pt6.jade # public/features.jade # public/resources/js/directives/live-example.js # tools/plunker-builder/indexHtmlTranslator.js
2016-09-08 05:20:01 -04:00
*dependencies*下的这些包是*运行*本应用的基础,而*devDependencies*下的只在*开发*此应用时才用得到。
通过为`install`命令添加`--production`参数,你在产品环境下安装时排除*devDependencies*下的包,就像这样:
code-example(format="." language="bash").
npm install my-application --production
a(id="dependencies")
.l-main-section
:marked
## *dependencies*
The `dependencies` section of `package.json` contains:
2016-05-26 08:50:46 -04:00
应用程序的`package.json`文件中,`dependencies`区下有三类包:
* ***Features*** - Feature packages give the application framework and utility capabilities.
Merge remote-tracking branch 'origin/master' # Conflicts: # README.md # public/_includes/_scripts-include.jade # public/docs/_examples/homepage-hello-world/ts/index.1.html # public/docs/_examples/homepage-tabs/ts/index.1.html # public/docs/_examples/homepage-todo/ts/index.1.html # public/docs/_examples/systemjs.config.plunker.build.js # public/docs/_examples/systemjs.config.plunker.js # public/docs/js/latest/cookbook/ts-to-js.jade # public/docs/ts/latest/_data.json # public/docs/ts/latest/cookbook/component-communication.jade # public/docs/ts/latest/cookbook/component-relative-paths.jade # public/docs/ts/latest/glossary.jade # public/docs/ts/latest/guide/_data.json # public/docs/ts/latest/guide/architecture.jade # public/docs/ts/latest/guide/attribute-directives.jade # public/docs/ts/latest/guide/dependency-injection.jade # public/docs/ts/latest/guide/index.jade # public/docs/ts/latest/guide/lifecycle-hooks.jade # public/docs/ts/latest/guide/ngmodule.jade # public/docs/ts/latest/guide/npm-packages.jade # public/docs/ts/latest/guide/security.jade # public/docs/ts/latest/guide/server-communication.jade # public/docs/ts/latest/guide/template-syntax.jade # public/docs/ts/latest/guide/typescript-configuration.jade # public/docs/ts/latest/index.jade # public/docs/ts/latest/quickstart.jade # public/docs/ts/latest/tutorial/_data.json # public/docs/ts/latest/tutorial/toh-pt6.jade # public/features.jade # public/resources/js/directives/live-example.js # tools/plunker-builder/indexHtmlTranslator.js
2016-09-08 05:20:01 -04:00
* ***特性*** - 特性包为应用程序提供了框架和工具方面的能力。
* ***Polyfills*** - Polyfills plug gaps in the browser's JavaScript implementation.
2016-05-26 08:50:46 -04:00
* ***填充(Polyfills)*** - 填充包弥合了不同浏览器上的JavaScript实现方面的差异。
2016-04-27 14:28:22 -04:00
* ***Other*** - Other libraries that support the application such as `bootstrap` for HTML widgets and styling.
2016-05-26 08:50:46 -04:00
* ***其它*** - 其它库对本应用提供支持,比如`bootstrap`包提供了HTML中的小部件和样式。
2016-04-27 14:28:22 -04:00
.l-main-section
:marked
### Feature Packages
2016-05-26 08:50:46 -04:00
### 特性包
2016-04-27 14:28:22 -04:00
***@angular/core*** - Critical runtime parts of the framework needed by every application.
Includes all metadata decorators, `Component`, `Directive`, dependency injection, and the component lifecycle hooks.
2016-05-26 08:50:46 -04:00
***@angular/core*** - 框架中关键的运行期部件,每一个应用都需要它。
包括所有的元数据装饰器:`Component`、`Directive`,依赖注入系统,以及组件生命周期钩子。
***@angular/common*** - The commonly needed services, pipes, and directives provided by the Angular team.
2016-04-27 14:28:22 -04:00
2016-05-26 08:50:46 -04:00
***@angular/common*** - 常用的那些由Angular开发组提供的服务、管道和指令。
2016-04-27 14:28:22 -04:00
***@angular/compiler*** - Angular's *Template Compiler*.
It understands templates and can convert them to code that makes the application run and render.
Typically you dont interact with the compiler directly; rather, you use it indirectly via `platform-browser-dynamic` or the offline template compiler.
2016-04-27 14:28:22 -04:00
2016-05-26 08:50:46 -04:00
***@angular/compiler*** - Angular的*模板编译器*。
它会理解模板,并且把模板转化成代码,以供应用程序运行和渲染。
开发人员通常不会直接跟这个编译器打交道,而是通过`platform-browser-dynamic`或离线模板编译器间接使用它。
2016-04-27 14:28:22 -04:00
***@angular/platform-browser*** - Everything DOM and browser related, especially the pieces that help render into DOM.
This package also includes the bootstrapStatic method for bootstrapping applications for production builds that pre-compile templates offline.
2016-05-26 08:50:46 -04:00
***@angular/platform-browser*** - 与DOM和浏览器相关的每样东西特别是帮助往DOM中渲染的那部分。
这个包还包含bootstrapStatic方法用来引导那些在产品构建时需要离线预编译模板的应用程序。
Merge remote-tracking branch 'origin/master' # Conflicts: # README.md # public/_includes/_scripts-include.jade # public/docs/_examples/homepage-hello-world/ts/index.1.html # public/docs/_examples/homepage-tabs/ts/index.1.html # public/docs/_examples/homepage-todo/ts/index.1.html # public/docs/_examples/systemjs.config.plunker.build.js # public/docs/_examples/systemjs.config.plunker.js # public/docs/js/latest/cookbook/ts-to-js.jade # public/docs/ts/latest/_data.json # public/docs/ts/latest/cookbook/component-communication.jade # public/docs/ts/latest/cookbook/component-relative-paths.jade # public/docs/ts/latest/glossary.jade # public/docs/ts/latest/guide/_data.json # public/docs/ts/latest/guide/architecture.jade # public/docs/ts/latest/guide/attribute-directives.jade # public/docs/ts/latest/guide/dependency-injection.jade # public/docs/ts/latest/guide/index.jade # public/docs/ts/latest/guide/lifecycle-hooks.jade # public/docs/ts/latest/guide/ngmodule.jade # public/docs/ts/latest/guide/npm-packages.jade # public/docs/ts/latest/guide/security.jade # public/docs/ts/latest/guide/server-communication.jade # public/docs/ts/latest/guide/template-syntax.jade # public/docs/ts/latest/guide/typescript-configuration.jade # public/docs/ts/latest/index.jade # public/docs/ts/latest/quickstart.jade # public/docs/ts/latest/tutorial/_data.json # public/docs/ts/latest/tutorial/toh-pt6.jade # public/features.jade # public/resources/js/directives/live-example.js # tools/plunker-builder/indexHtmlTranslator.js
2016-09-08 05:20:01 -04:00
***@angular/platform-browser-dynamic*** - Includes (https://angular.io/docs/ts/latest/api/core/index/Provider-type-alias.html) and a [bootstrap](https://angular.io/docs/ts/latest/guide/ngmodule.html#!#bootstrap) method for applications that
compile templates on the client. Dont use offline compilation.
Use this package for bootstrapping during development and for bootstrapping plunker samples.
2016-04-27 14:28:22 -04:00
Merge remote-tracking branch 'origin/master' # Conflicts: # README.md # public/_includes/_scripts-include.jade # public/docs/_examples/homepage-hello-world/ts/index.1.html # public/docs/_examples/homepage-tabs/ts/index.1.html # public/docs/_examples/homepage-todo/ts/index.1.html # public/docs/_examples/systemjs.config.plunker.build.js # public/docs/_examples/systemjs.config.plunker.js # public/docs/js/latest/cookbook/ts-to-js.jade # public/docs/ts/latest/_data.json # public/docs/ts/latest/cookbook/component-communication.jade # public/docs/ts/latest/cookbook/component-relative-paths.jade # public/docs/ts/latest/glossary.jade # public/docs/ts/latest/guide/_data.json # public/docs/ts/latest/guide/architecture.jade # public/docs/ts/latest/guide/attribute-directives.jade # public/docs/ts/latest/guide/dependency-injection.jade # public/docs/ts/latest/guide/index.jade # public/docs/ts/latest/guide/lifecycle-hooks.jade # public/docs/ts/latest/guide/ngmodule.jade # public/docs/ts/latest/guide/npm-packages.jade # public/docs/ts/latest/guide/security.jade # public/docs/ts/latest/guide/server-communication.jade # public/docs/ts/latest/guide/template-syntax.jade # public/docs/ts/latest/guide/typescript-configuration.jade # public/docs/ts/latest/index.jade # public/docs/ts/latest/quickstart.jade # public/docs/ts/latest/tutorial/_data.json # public/docs/ts/latest/tutorial/toh-pt6.jade # public/features.jade # public/resources/js/directives/live-example.js # tools/plunker-builder/indexHtmlTranslator.js
2016-09-08 05:20:01 -04:00
***@angular/platform-browser-dynamic*** - 为应用程序提供一些[提供商](https://angular.io/docs/ts/latest/api/core/index/Provider-type-alias.html)和[bootstrap](https://angular.io/docs/ts/latest/guide/ngmodule.html#!#bootstrap)方法,以便在客户端编译模板。不要用于离线编译。
2016-05-26 08:50:46 -04:00
我们使用这个包在开发期间引导应用以及引导plunker中的范例。
***@angular/http*** - Angular's http client.
2016-04-27 14:28:22 -04:00
2016-05-26 08:50:46 -04:00
***@angular/http*** - Angular的HTTP客户端。
2016-04-27 14:28:22 -04:00
***@angular/router*** - Component router.
***@angular/router*** - 路由器。
2016-05-26 08:50:46 -04:00
2016-04-27 14:28:22 -04:00
***@angular/upgrade*** - Set of utilities for upgrading Angular 1 applications.
2016-05-26 08:50:46 -04:00
***@angular/upgrade*** - 一组用于升级Angular 1应用的工具。
***[system.js](https://github.com/systemjs/systemjs)*** - A dynamic module loader compatible with the
[ES2015 module](http://www.2ality.com/2014/09/es6-modules-final.html) specification.
Other viable choices include the well-regarded [webpack](https://webpack.github.io/).
2016-05-26 08:50:46 -04:00
***[system.js](https://github.com/systemjs/systemjs)*** - 是一个动态的模块加载器,
2016-06-05 17:48:50 -04:00
与[ES2015模块](http://www.2ality.com/2014/09/es6-modules-final.html)规范兼容。
2016-09-25 14:50:45 -04:00
还有很多其它选择,比如广受欢迎的[webpack](https://webpack.github.io/)。
2016-06-05 17:48:50 -04:00
SystemJS被用在了我们的文档范例中。因为它能工作。
2016-05-26 08:50:46 -04:00
Your future applications are likely to require additional packages that provide
HTML controls, themes, data access, and various utilities.
Merge remote-tracking branch 'origin/master' # Conflicts: # README.md # public/_includes/_scripts-include.jade # public/docs/_examples/homepage-hello-world/ts/index.1.html # public/docs/_examples/homepage-tabs/ts/index.1.html # public/docs/_examples/homepage-todo/ts/index.1.html # public/docs/_examples/systemjs.config.plunker.build.js # public/docs/_examples/systemjs.config.plunker.js # public/docs/js/latest/cookbook/ts-to-js.jade # public/docs/ts/latest/_data.json # public/docs/ts/latest/cookbook/component-communication.jade # public/docs/ts/latest/cookbook/component-relative-paths.jade # public/docs/ts/latest/glossary.jade # public/docs/ts/latest/guide/_data.json # public/docs/ts/latest/guide/architecture.jade # public/docs/ts/latest/guide/attribute-directives.jade # public/docs/ts/latest/guide/dependency-injection.jade # public/docs/ts/latest/guide/index.jade # public/docs/ts/latest/guide/lifecycle-hooks.jade # public/docs/ts/latest/guide/ngmodule.jade # public/docs/ts/latest/guide/npm-packages.jade # public/docs/ts/latest/guide/security.jade # public/docs/ts/latest/guide/server-communication.jade # public/docs/ts/latest/guide/template-syntax.jade # public/docs/ts/latest/guide/typescript-configuration.jade # public/docs/ts/latest/index.jade # public/docs/ts/latest/quickstart.jade # public/docs/ts/latest/tutorial/_data.json # public/docs/ts/latest/tutorial/toh-pt6.jade # public/features.jade # public/resources/js/directives/live-example.js # tools/plunker-builder/indexHtmlTranslator.js
2016-09-08 05:20:01 -04:00
今后应用程序很可能还会需要一些额外的包比如HTML控件、主题、数据访问以及其它多种工具。
2016-05-26 08:50:46 -04:00
a(id="polyfills")
.l-main-section
:marked
### Polyfill packages
2016-05-26 08:50:46 -04:00
### 填充(Polyfile)包
Angular requires certain [polyfills](https://en.wikipedia.org/wiki/Polyfill) in the application environment.
Install these polyfills using the npm packages that Angular lists in the *peerDependencies* section of its `package.json`.
2016-06-05 17:48:50 -04:00
在应用程序的运行环境中Angular需要某些[填充库](https://en.wikipedia.org/wiki/Polyfill)。
我们通过特定的npm包来安装这些填充库Angular本身把它列在了`package.json`中的*peerDependencies*区。
2016-05-26 08:50:46 -04:00
You must list these packages in the `dependencies` section of your own `package.json`.
2016-05-26 08:50:46 -04:00
但我们必须把它列在我们`package.json`文件的`dependencies`区。
.l-sub-section
:marked
For background on this requirement, see [Why peerDependencies?](#why-peer-dependencies).
2016-05-26 08:50:46 -04:00
查看下面的“[为什么用peerDependencies?](#why-peer-dependencies)”,以了解这项需求的背景。
:marked
***core-js*** - Patches the global context (window) with essential features of ES2015 (ES6).
Merge remote-tracking branch 'origin/master' # Conflicts: # README.md # public/_includes/_scripts-include.jade # public/docs/_examples/homepage-hello-world/ts/index.1.html # public/docs/_examples/homepage-tabs/ts/index.1.html # public/docs/_examples/homepage-todo/ts/index.1.html # public/docs/_examples/systemjs.config.plunker.build.js # public/docs/_examples/systemjs.config.plunker.js # public/docs/js/latest/cookbook/ts-to-js.jade # public/docs/ts/latest/_data.json # public/docs/ts/latest/cookbook/component-communication.jade # public/docs/ts/latest/cookbook/component-relative-paths.jade # public/docs/ts/latest/glossary.jade # public/docs/ts/latest/guide/_data.json # public/docs/ts/latest/guide/architecture.jade # public/docs/ts/latest/guide/attribute-directives.jade # public/docs/ts/latest/guide/dependency-injection.jade # public/docs/ts/latest/guide/index.jade # public/docs/ts/latest/guide/lifecycle-hooks.jade # public/docs/ts/latest/guide/ngmodule.jade # public/docs/ts/latest/guide/npm-packages.jade # public/docs/ts/latest/guide/security.jade # public/docs/ts/latest/guide/server-communication.jade # public/docs/ts/latest/guide/template-syntax.jade # public/docs/ts/latest/guide/typescript-configuration.jade # public/docs/ts/latest/index.jade # public/docs/ts/latest/quickstart.jade # public/docs/ts/latest/tutorial/_data.json # public/docs/ts/latest/tutorial/toh-pt6.jade # public/features.jade # public/resources/js/directives/live-example.js # tools/plunker-builder/indexHtmlTranslator.js
2016-09-08 05:20:01 -04:00
You may substitute an alternative polyfill that provides the same core APIs.
When these APIs are implemented by the major browsers, this dependency will become unnecessary.
Merge remote-tracking branch 'origin/master' # Conflicts: # README.md # public/_includes/_scripts-include.jade # public/docs/_examples/homepage-hello-world/ts/index.1.html # public/docs/_examples/homepage-tabs/ts/index.1.html # public/docs/_examples/homepage-todo/ts/index.1.html # public/docs/_examples/systemjs.config.plunker.build.js # public/docs/_examples/systemjs.config.plunker.js # public/docs/js/latest/cookbook/ts-to-js.jade # public/docs/ts/latest/_data.json # public/docs/ts/latest/cookbook/component-communication.jade # public/docs/ts/latest/cookbook/component-relative-paths.jade # public/docs/ts/latest/glossary.jade # public/docs/ts/latest/guide/_data.json # public/docs/ts/latest/guide/architecture.jade # public/docs/ts/latest/guide/attribute-directives.jade # public/docs/ts/latest/guide/dependency-injection.jade # public/docs/ts/latest/guide/index.jade # public/docs/ts/latest/guide/lifecycle-hooks.jade # public/docs/ts/latest/guide/ngmodule.jade # public/docs/ts/latest/guide/npm-packages.jade # public/docs/ts/latest/guide/security.jade # public/docs/ts/latest/guide/server-communication.jade # public/docs/ts/latest/guide/template-syntax.jade # public/docs/ts/latest/guide/typescript-configuration.jade # public/docs/ts/latest/index.jade # public/docs/ts/latest/quickstart.jade # public/docs/ts/latest/tutorial/_data.json # public/docs/ts/latest/tutorial/toh-pt6.jade # public/features.jade # public/resources/js/directives/live-example.js # tools/plunker-builder/indexHtmlTranslator.js
2016-09-08 05:20:01 -04:00
***core-js*** - 为全局上下文(window)打的补丁提供了ES2015(ES6)的很多基础特性。
我们也可以把它换成提供了相同内核API的其它填充库。
一旦所有的“主流浏览器”都实现了这些API这个依赖就可以去掉了。
***reflect-metadata*** - A dependency shared between Angular and the ***TypeScript compiler***.
You can update a TypeScript package without upgrading Angular,
which is why this is a dependency of the application and not a dependency of Angular.
2016-05-26 08:50:46 -04:00
***reflect-metadata*** - 一个由Angular和***TypeScript***编译器共享的依赖包。
开发人员需要能单独更新TypeScript包而不用升级Angular。这就是为什么把它放在本应用程序的依赖中而不是Angular的依赖中。
***rxjs*** - A polyfill for the [Observables specification](https://github.com/zenparsing/es-observable) currently before the
[TC39](http://www.ecma-international.org/memento/TC39.htm) committee that determines standards for the JavaScript language.
You can pick a preferred version of *rxjs* (within a compatible version range)
without waiting for Angular updates.
2016-06-05 17:48:50 -04:00
***rxjs*** - 一个为[可观察对象(Observable)规范](https://github.com/zenparsing/es-observable)提供的填充库,该规范已经提交给了
2016-05-26 08:50:46 -04:00
[TC39](http://www.ecma-international.org/memento/TC39.htm)委员会以决定是否要在JavaScript语言中进行标准化。
开发人员应该能在兼容的版本中选择一个喜欢的*rxjs*版本而不用等Angular升级。
***zone.js*** - A polyfill for the [Zone specification](https://gist.github.com/mhevery/63fdcdf7c65886051d55) currently before the
[TC39](http://www.ecma-international.org/memento/TC39.htm) committee that determines standards for the JavaScript language.
You can pick a preferred version of *zone.js* to use (within a compatible version range)
without waiting for Angular updates.
2016-05-26 08:50:46 -04:00
2016-06-05 17:48:50 -04:00
***zone.js*** - 一个为[Zone规范](https://gist.github.com/mhevery/63fdcdf7c65886051d55)提供的填充库,该规范已经提交给了
2016-05-26 08:50:46 -04:00
[TC39](http://www.ecma-international.org/memento/TC39.htm)委员会以决定是否要在JavaScript语言中进行标准化。
开发人员应该能在兼容的版本中选择一个喜欢的*zone.js*版本而不用等Angular升级。
2016-04-27 14:28:22 -04:00
a(id="other")
.l-main-section
:marked
### Other helper libraries
2016-05-26 08:50:46 -04:00
### 其它辅助库
2016-04-27 14:28:22 -04:00
***angular-in-memory-web-api*** - An Angular-supported library that simulates a remote server's web api
2016-04-27 14:28:22 -04:00
without requiring an actual server or real http calls.
Good for demos, samples, and early stage development (before we even have a server).
Read about it in the [Http Client](server-communication.html#appendix-tour-of-heroes-in-memory-server) page.
2016-04-27 14:28:22 -04:00
***angular-in-memory-web-api*** - 一个Angular的支持库它能模拟一个远端服务器的Web API而不需要依赖一个真实的服务器或发起真实的HTTP调用。
对演示、文档范例和开发的早期阶段(那时候我们可能还没有服务器呢)非常有用。
2016-05-26 08:50:46 -04:00
请到[Http客户端](server-communication.html#appendix-tour-of-heroes-in-memory-server)一章中了解更多知识。
***bootstrap*** - [Bootstrap](http://getbootstrap.com/) is a popular HTML and CSS framework for designing responsive web apps.
Some of the samples improve their appearance with *bootstrap*.
2016-04-27 14:28:22 -04:00
2016-06-05 17:48:50 -04:00
***bootstrap*** - [bootstrap](http://getbootstrap.com/)是一个广受欢迎的HTML和CSS框架可用来设计响应式网络应用。
2016-05-26 08:50:46 -04:00
有些文档中的范例使用了*bootstrap*来强化它们的外观。
a(id="dev-dependencies")
.l-main-section
:marked
## *devDependencies*
The packages listed in the *devDependencies* section of the `package.json` help you develop the application.
You don't have to deploy them with the production application although there is no harm in doing so.
2016-05-26 08:50:46 -04:00
列在`package.json`文件中*devDependencies*区的包会帮助我们开发该应用程序。
Merge remote-tracking branch 'origin/master' # Conflicts: # README.md # public/_includes/_scripts-include.jade # public/docs/_examples/homepage-hello-world/ts/index.1.html # public/docs/_examples/homepage-tabs/ts/index.1.html # public/docs/_examples/homepage-todo/ts/index.1.html # public/docs/_examples/systemjs.config.plunker.build.js # public/docs/_examples/systemjs.config.plunker.js # public/docs/js/latest/cookbook/ts-to-js.jade # public/docs/ts/latest/_data.json # public/docs/ts/latest/cookbook/component-communication.jade # public/docs/ts/latest/cookbook/component-relative-paths.jade # public/docs/ts/latest/glossary.jade # public/docs/ts/latest/guide/_data.json # public/docs/ts/latest/guide/architecture.jade # public/docs/ts/latest/guide/attribute-directives.jade # public/docs/ts/latest/guide/dependency-injection.jade # public/docs/ts/latest/guide/index.jade # public/docs/ts/latest/guide/lifecycle-hooks.jade # public/docs/ts/latest/guide/ngmodule.jade # public/docs/ts/latest/guide/npm-packages.jade # public/docs/ts/latest/guide/security.jade # public/docs/ts/latest/guide/server-communication.jade # public/docs/ts/latest/guide/template-syntax.jade # public/docs/ts/latest/guide/typescript-configuration.jade # public/docs/ts/latest/index.jade # public/docs/ts/latest/quickstart.jade # public/docs/ts/latest/tutorial/_data.json # public/docs/ts/latest/tutorial/toh-pt6.jade # public/features.jade # public/resources/js/directives/live-example.js # tools/plunker-builder/indexHtmlTranslator.js
2016-09-08 05:20:01 -04:00
我们不用把它们部署到产品环境的应用程序中 —— 虽然这样做也没什么坏处。
***[concurrently](https://www.npmjs.com/package/concurrently)*** -
A utility to run multiple *npm* commands concurrently on OS/X, Windows, and Linux operating systems.
2016-05-26 08:50:46 -04:00
***[concurrently](https://www.npmjs.com/package/concurrently)*** - 一个用来在OS/X、Windows和Linux操作系统上同时运行多个*npm*命令的工具
***[lite-server](https://www.npmjs.com/package/lite-server)*** -
A light-weight, static file server, by [John Papa](http://johnpapa.net/)
with excellent support for Angular apps that use routing.
2016-05-26 08:50:46 -04:00
***[lite-server](https://www.npmjs.com/package/lite-server)*** - 一个轻量级、静态的服务器,
由[John Papa](http://johnpapa.net/)开发和维护。对使用到路由的Angular程序提供了很好的支持。
***[typescript](https://www.npmjs.com/package/typescript)*** -
The TypeScript language server, including the *tsc* TypeScript compiler.
2016-05-26 08:50:46 -04:00
***[typescript](https://www.npmjs.com/package/typescript)*** - TypeScript语言的服务器包含了TypeScript编译器*tsc*。
***[typings](https://www.npmjs.com/package/typings)*** - A manager for TypeScript definition files.
Read more about it in the [TypeScript Configuration](typescript-configuration.html#typings) page.
2016-06-05 17:48:50 -04:00
***[typings](https://www.npmjs.com/package/typings)*** - 一个“TypeScript定义”文件管理器。
Merge remote-tracking branch 'origin/master' # Conflicts: # README.md # public/_includes/_scripts-include.jade # public/docs/_examples/homepage-hello-world/ts/index.1.html # public/docs/_examples/homepage-tabs/ts/index.1.html # public/docs/_examples/homepage-todo/ts/index.1.html # public/docs/_examples/systemjs.config.plunker.build.js # public/docs/_examples/systemjs.config.plunker.js # public/docs/js/latest/cookbook/ts-to-js.jade # public/docs/ts/latest/_data.json # public/docs/ts/latest/cookbook/component-communication.jade # public/docs/ts/latest/cookbook/component-relative-paths.jade # public/docs/ts/latest/glossary.jade # public/docs/ts/latest/guide/_data.json # public/docs/ts/latest/guide/architecture.jade # public/docs/ts/latest/guide/attribute-directives.jade # public/docs/ts/latest/guide/dependency-injection.jade # public/docs/ts/latest/guide/index.jade # public/docs/ts/latest/guide/lifecycle-hooks.jade # public/docs/ts/latest/guide/ngmodule.jade # public/docs/ts/latest/guide/npm-packages.jade # public/docs/ts/latest/guide/security.jade # public/docs/ts/latest/guide/server-communication.jade # public/docs/ts/latest/guide/template-syntax.jade # public/docs/ts/latest/guide/typescript-configuration.jade # public/docs/ts/latest/index.jade # public/docs/ts/latest/quickstart.jade # public/docs/ts/latest/tutorial/_data.json # public/docs/ts/latest/tutorial/toh-pt6.jade # public/features.jade # public/resources/js/directives/live-example.js # tools/plunker-builder/indexHtmlTranslator.js
2016-09-08 05:20:01 -04:00
要了解更多,请参见[TypeScript配置](typescript-configuration.html#typings)页。
2016-05-26 08:50:46 -04:00
.l-main-section
a(id="why-peer-dependencies")
:marked
## Why *peerDependencies*?
2016-05-26 08:50:46 -04:00
## 为什么使用*peerDependencies*
There isn't a *peerDependencies* section in the QuickStart `package.json`.
But Angular has a *peerDependencies* section in
*its* package.json, which has important consequences for your application.
2016-05-26 08:50:46 -04:00
在“快速起步”的`package.json`文件中,并没有*peerDependencies*区。
但是Angular本身在[*它自己的* package.json](https://github.com/angular/angular/blob/master/modules/angular2/package.json)中有,
它对我们的应用程序有重要的影响。
It explains why you load the [polyfill](#polyfills) *dependency* packages in the QuickStart `package.json`,
and why you'll need those packages in your own applications.
2016-05-26 08:50:46 -04:00
它解释了为什么我们要在“快速起步”的`package.json`文件中加载这些[填充库(polyfill)](#polyfills)依赖包,
以及为什么我们在自己的应用中会需要它们。
An explanation of [peer dependencies](https://nodejs.org/en/blog/npm/peer-dependencies/) follows.
Merge remote-tracking branch 'origin/master' # Conflicts: # README.md # public/_includes/_scripts-include.jade # public/docs/_examples/homepage-hello-world/ts/index.1.html # public/docs/_examples/homepage-tabs/ts/index.1.html # public/docs/_examples/homepage-todo/ts/index.1.html # public/docs/_examples/systemjs.config.plunker.build.js # public/docs/_examples/systemjs.config.plunker.js # public/docs/js/latest/cookbook/ts-to-js.jade # public/docs/ts/latest/_data.json # public/docs/ts/latest/cookbook/component-communication.jade # public/docs/ts/latest/cookbook/component-relative-paths.jade # public/docs/ts/latest/glossary.jade # public/docs/ts/latest/guide/_data.json # public/docs/ts/latest/guide/architecture.jade # public/docs/ts/latest/guide/attribute-directives.jade # public/docs/ts/latest/guide/dependency-injection.jade # public/docs/ts/latest/guide/index.jade # public/docs/ts/latest/guide/lifecycle-hooks.jade # public/docs/ts/latest/guide/ngmodule.jade # public/docs/ts/latest/guide/npm-packages.jade # public/docs/ts/latest/guide/security.jade # public/docs/ts/latest/guide/server-communication.jade # public/docs/ts/latest/guide/template-syntax.jade # public/docs/ts/latest/guide/typescript-configuration.jade # public/docs/ts/latest/index.jade # public/docs/ts/latest/quickstart.jade # public/docs/ts/latest/tutorial/_data.json # public/docs/ts/latest/tutorial/toh-pt6.jade # public/features.jade # public/resources/js/directives/live-example.js # tools/plunker-builder/indexHtmlTranslator.js
2016-09-08 05:20:01 -04:00
然后是对[平级依赖(peer dependencies)](https://nodejs.org/en/blog/npm/peer-dependencies/)的简短解释。
2016-05-26 08:50:46 -04:00
Packages depend on other packages. For example, your application depends on the Angular package.
Merge remote-tracking branch 'origin/master' # Conflicts: # README.md # public/_includes/_scripts-include.jade # public/docs/_examples/homepage-hello-world/ts/index.1.html # public/docs/_examples/homepage-tabs/ts/index.1.html # public/docs/_examples/homepage-todo/ts/index.1.html # public/docs/_examples/systemjs.config.plunker.build.js # public/docs/_examples/systemjs.config.plunker.js # public/docs/js/latest/cookbook/ts-to-js.jade # public/docs/ts/latest/_data.json # public/docs/ts/latest/cookbook/component-communication.jade # public/docs/ts/latest/cookbook/component-relative-paths.jade # public/docs/ts/latest/glossary.jade # public/docs/ts/latest/guide/_data.json # public/docs/ts/latest/guide/architecture.jade # public/docs/ts/latest/guide/attribute-directives.jade # public/docs/ts/latest/guide/dependency-injection.jade # public/docs/ts/latest/guide/index.jade # public/docs/ts/latest/guide/lifecycle-hooks.jade # public/docs/ts/latest/guide/ngmodule.jade # public/docs/ts/latest/guide/npm-packages.jade # public/docs/ts/latest/guide/security.jade # public/docs/ts/latest/guide/server-communication.jade # public/docs/ts/latest/guide/template-syntax.jade # public/docs/ts/latest/guide/typescript-configuration.jade # public/docs/ts/latest/index.jade # public/docs/ts/latest/quickstart.jade # public/docs/ts/latest/tutorial/_data.json # public/docs/ts/latest/tutorial/toh-pt6.jade # public/features.jade # public/resources/js/directives/live-example.js # tools/plunker-builder/indexHtmlTranslator.js
2016-09-08 05:20:01 -04:00
每个包都依赖其它的包比如我们的应用程序就依赖于Angular包。
2016-05-26 08:50:46 -04:00
Two packages, "A" and "B", could depend on the same third package "C".
"A" and "B" might both list "C" among their *dependencies*.
Merge remote-tracking branch 'origin/master' # Conflicts: # README.md # public/_includes/_scripts-include.jade # public/docs/_examples/homepage-hello-world/ts/index.1.html # public/docs/_examples/homepage-tabs/ts/index.1.html # public/docs/_examples/homepage-todo/ts/index.1.html # public/docs/_examples/systemjs.config.plunker.build.js # public/docs/_examples/systemjs.config.plunker.js # public/docs/js/latest/cookbook/ts-to-js.jade # public/docs/ts/latest/_data.json # public/docs/ts/latest/cookbook/component-communication.jade # public/docs/ts/latest/cookbook/component-relative-paths.jade # public/docs/ts/latest/glossary.jade # public/docs/ts/latest/guide/_data.json # public/docs/ts/latest/guide/architecture.jade # public/docs/ts/latest/guide/attribute-directives.jade # public/docs/ts/latest/guide/dependency-injection.jade # public/docs/ts/latest/guide/index.jade # public/docs/ts/latest/guide/lifecycle-hooks.jade # public/docs/ts/latest/guide/ngmodule.jade # public/docs/ts/latest/guide/npm-packages.jade # public/docs/ts/latest/guide/security.jade # public/docs/ts/latest/guide/server-communication.jade # public/docs/ts/latest/guide/template-syntax.jade # public/docs/ts/latest/guide/typescript-configuration.jade # public/docs/ts/latest/index.jade # public/docs/ts/latest/quickstart.jade # public/docs/ts/latest/tutorial/_data.json # public/docs/ts/latest/tutorial/toh-pt6.jade # public/features.jade # public/resources/js/directives/live-example.js # tools/plunker-builder/indexHtmlTranslator.js
2016-09-08 05:20:01 -04:00
两个包,"A"和"B",可能依赖共同的第三个包"C"。
"A"和"B"可能都在它们的*dependencies*中列出了"C"。
2016-05-26 08:50:46 -04:00
Merge remote-tracking branch 'origin/master' # Conflicts: # README.md # public/_includes/_scripts-include.jade # public/docs/_examples/homepage-hello-world/ts/index.1.html # public/docs/_examples/homepage-tabs/ts/index.1.html # public/docs/_examples/homepage-todo/ts/index.1.html # public/docs/_examples/systemjs.config.plunker.build.js # public/docs/_examples/systemjs.config.plunker.js # public/docs/js/latest/cookbook/ts-to-js.jade # public/docs/ts/latest/_data.json # public/docs/ts/latest/cookbook/component-communication.jade # public/docs/ts/latest/cookbook/component-relative-paths.jade # public/docs/ts/latest/glossary.jade # public/docs/ts/latest/guide/_data.json # public/docs/ts/latest/guide/architecture.jade # public/docs/ts/latest/guide/attribute-directives.jade # public/docs/ts/latest/guide/dependency-injection.jade # public/docs/ts/latest/guide/index.jade # public/docs/ts/latest/guide/lifecycle-hooks.jade # public/docs/ts/latest/guide/ngmodule.jade # public/docs/ts/latest/guide/npm-packages.jade # public/docs/ts/latest/guide/security.jade # public/docs/ts/latest/guide/server-communication.jade # public/docs/ts/latest/guide/template-syntax.jade # public/docs/ts/latest/guide/typescript-configuration.jade # public/docs/ts/latest/index.jade # public/docs/ts/latest/quickstart.jade # public/docs/ts/latest/tutorial/_data.json # public/docs/ts/latest/tutorial/toh-pt6.jade # public/features.jade # public/resources/js/directives/live-example.js # tools/plunker-builder/indexHtmlTranslator.js
2016-09-08 05:20:01 -04:00
What if "A" and "B" depend on different versions of "C" ("C1" and "C2"). The npm package system supports that!
It installs "C1" in the `node_modules` folder for "A" and "C2" in the `node_modules` folder for "B".
Now "A" and "B" have their own copies of "C" and they run without interferring with one another.
Merge remote-tracking branch 'origin/master' # Conflicts: # README.md # public/_includes/_scripts-include.jade # public/docs/_examples/homepage-hello-world/ts/index.1.html # public/docs/_examples/homepage-tabs/ts/index.1.html # public/docs/_examples/homepage-todo/ts/index.1.html # public/docs/_examples/systemjs.config.plunker.build.js # public/docs/_examples/systemjs.config.plunker.js # public/docs/js/latest/cookbook/ts-to-js.jade # public/docs/ts/latest/_data.json # public/docs/ts/latest/cookbook/component-communication.jade # public/docs/ts/latest/cookbook/component-relative-paths.jade # public/docs/ts/latest/glossary.jade # public/docs/ts/latest/guide/_data.json # public/docs/ts/latest/guide/architecture.jade # public/docs/ts/latest/guide/attribute-directives.jade # public/docs/ts/latest/guide/dependency-injection.jade # public/docs/ts/latest/guide/index.jade # public/docs/ts/latest/guide/lifecycle-hooks.jade # public/docs/ts/latest/guide/ngmodule.jade # public/docs/ts/latest/guide/npm-packages.jade # public/docs/ts/latest/guide/security.jade # public/docs/ts/latest/guide/server-communication.jade # public/docs/ts/latest/guide/template-syntax.jade # public/docs/ts/latest/guide/typescript-configuration.jade # public/docs/ts/latest/index.jade # public/docs/ts/latest/quickstart.jade # public/docs/ts/latest/tutorial/_data.json # public/docs/ts/latest/tutorial/toh-pt6.jade # public/features.jade # public/resources/js/directives/live-example.js # tools/plunker-builder/indexHtmlTranslator.js
2016-09-08 05:20:01 -04:00
如果"A"和"B"依赖于"C"的不同版本("C1"和"C2")。npm包管理系统也能支持
它会把"C1"安装到"A"的`node_modules`目录下给"A"用,把"C2"安装到"B"的`node_modules`目录下给"B"用。
现在,"A"和"B"都有了它们自己的一份"C"的复本,它们运行起来也互不干扰。
2016-05-26 08:50:46 -04:00
But there is a problem. Package "A" may require the presence of "C1" without actually calling upon it directly.
"A" may only work if *everyone is using "C1"*. It falls down if any part of the application relies on "C2".
Merge remote-tracking branch 'origin/master' # Conflicts: # README.md # public/_includes/_scripts-include.jade # public/docs/_examples/homepage-hello-world/ts/index.1.html # public/docs/_examples/homepage-tabs/ts/index.1.html # public/docs/_examples/homepage-todo/ts/index.1.html # public/docs/_examples/systemjs.config.plunker.build.js # public/docs/_examples/systemjs.config.plunker.js # public/docs/js/latest/cookbook/ts-to-js.jade # public/docs/ts/latest/_data.json # public/docs/ts/latest/cookbook/component-communication.jade # public/docs/ts/latest/cookbook/component-relative-paths.jade # public/docs/ts/latest/glossary.jade # public/docs/ts/latest/guide/_data.json # public/docs/ts/latest/guide/architecture.jade # public/docs/ts/latest/guide/attribute-directives.jade # public/docs/ts/latest/guide/dependency-injection.jade # public/docs/ts/latest/guide/index.jade # public/docs/ts/latest/guide/lifecycle-hooks.jade # public/docs/ts/latest/guide/ngmodule.jade # public/docs/ts/latest/guide/npm-packages.jade # public/docs/ts/latest/guide/security.jade # public/docs/ts/latest/guide/server-communication.jade # public/docs/ts/latest/guide/template-syntax.jade # public/docs/ts/latest/guide/typescript-configuration.jade # public/docs/ts/latest/index.jade # public/docs/ts/latest/quickstart.jade # public/docs/ts/latest/tutorial/_data.json # public/docs/ts/latest/tutorial/toh-pt6.jade # public/features.jade # public/resources/js/directives/live-example.js # tools/plunker-builder/indexHtmlTranslator.js
2016-09-08 05:20:01 -04:00
但是有一个问题。包"A"可能只需要"C1"出现就行,而实际上并不会直接调用它。
"A"可能只有当*每个人都使用"C1"时*才能正常工作。如果程序中的任何一个部分依赖了"C2",它就会失败。
2016-05-26 08:50:46 -04:00
The solution is for "A" to declare that "C1" is a *peer dependency*.
Merge remote-tracking branch 'origin/master' # Conflicts: # README.md # public/_includes/_scripts-include.jade # public/docs/_examples/homepage-hello-world/ts/index.1.html # public/docs/_examples/homepage-tabs/ts/index.1.html # public/docs/_examples/homepage-todo/ts/index.1.html # public/docs/_examples/systemjs.config.plunker.build.js # public/docs/_examples/systemjs.config.plunker.js # public/docs/js/latest/cookbook/ts-to-js.jade # public/docs/ts/latest/_data.json # public/docs/ts/latest/cookbook/component-communication.jade # public/docs/ts/latest/cookbook/component-relative-paths.jade # public/docs/ts/latest/glossary.jade # public/docs/ts/latest/guide/_data.json # public/docs/ts/latest/guide/architecture.jade # public/docs/ts/latest/guide/attribute-directives.jade # public/docs/ts/latest/guide/dependency-injection.jade # public/docs/ts/latest/guide/index.jade # public/docs/ts/latest/guide/lifecycle-hooks.jade # public/docs/ts/latest/guide/ngmodule.jade # public/docs/ts/latest/guide/npm-packages.jade # public/docs/ts/latest/guide/security.jade # public/docs/ts/latest/guide/server-communication.jade # public/docs/ts/latest/guide/template-syntax.jade # public/docs/ts/latest/guide/typescript-configuration.jade # public/docs/ts/latest/index.jade # public/docs/ts/latest/quickstart.jade # public/docs/ts/latest/tutorial/_data.json # public/docs/ts/latest/tutorial/toh-pt6.jade # public/features.jade # public/resources/js/directives/live-example.js # tools/plunker-builder/indexHtmlTranslator.js
2016-09-08 05:20:01 -04:00
要想解决这个问题,"A"就需要把"C1"定义为它的*平级依赖*。
2016-05-26 08:50:46 -04:00
The difference between a `dependency` and a `peerDependency` is roughly this:
2016-05-26 08:50:46 -04:00
在`dependencies`和`peerDependencies`之间的区别大致是这样的:
>A **dependency** says, "I need this thing directly available to *me*."
2016-05-26 08:50:46 -04:00
>**dependency**说:“我需要这东西*对我*直接可用。”
>
>A **peerDependency** says, "If you want to use me, you need this thing available to *you*."
2016-05-26 08:50:46 -04:00
>
2016-06-05 17:48:50 -04:00
>**peerDependency**说:“如果你想使用我,你得先确保这东西*对你*可用”
The Angular `package.json` specifies several *peer dependency* packages,
each pinned to a particular version of a third-party package.
2016-05-26 08:50:46 -04:00
2016-06-05 17:48:50 -04:00
Angular就存在这个问题。
2016-05-26 08:50:46 -04:00
因此Angular的`package.json`中指定了一系列*平级依赖*包,
把每个第三方包都固定在一个特定的版本上。
### We must install Angular's *peerDependencies* ourselves.
Merge remote-tracking branch 'origin/master' # Conflicts: # README.md # public/_includes/_scripts-include.jade # public/docs/_examples/homepage-hello-world/ts/index.1.html # public/docs/_examples/homepage-tabs/ts/index.1.html # public/docs/_examples/homepage-todo/ts/index.1.html # public/docs/_examples/systemjs.config.plunker.build.js # public/docs/_examples/systemjs.config.plunker.js # public/docs/js/latest/cookbook/ts-to-js.jade # public/docs/ts/latest/_data.json # public/docs/ts/latest/cookbook/component-communication.jade # public/docs/ts/latest/cookbook/component-relative-paths.jade # public/docs/ts/latest/glossary.jade # public/docs/ts/latest/guide/_data.json # public/docs/ts/latest/guide/architecture.jade # public/docs/ts/latest/guide/attribute-directives.jade # public/docs/ts/latest/guide/dependency-injection.jade # public/docs/ts/latest/guide/index.jade # public/docs/ts/latest/guide/lifecycle-hooks.jade # public/docs/ts/latest/guide/ngmodule.jade # public/docs/ts/latest/guide/npm-packages.jade # public/docs/ts/latest/guide/security.jade # public/docs/ts/latest/guide/server-communication.jade # public/docs/ts/latest/guide/template-syntax.jade # public/docs/ts/latest/guide/typescript-configuration.jade # public/docs/ts/latest/index.jade # public/docs/ts/latest/quickstart.jade # public/docs/ts/latest/tutorial/_data.json # public/docs/ts/latest/tutorial/toh-pt6.jade # public/features.jade # public/resources/js/directives/live-example.js # tools/plunker-builder/indexHtmlTranslator.js
2016-09-08 05:20:01 -04:00
### 我们必须自己安装Angular的*peerDependencies*。
When *npm* installs packages listed in *your* `dependencies` section,
it also installs the packages listed within *their* packages `dependencies` sections.
The process is recursive.
2016-06-05 17:48:50 -04:00
当*npm*安装那些在*我们的*`dependencies`区指定的包时,
2016-05-26 08:50:46 -04:00
它也会同时安装上在*那些包*的`dependencies`区所指定的那些包。
这个安装过程是递归的。
However, as of version 3, *npm* does *not* install packages listed in *peerDependencies* sections.
2016-06-05 17:48:50 -04:00
但是在npm的第三版中*它不会*安装列在*peerDependencies*区的那些包。
2016-05-26 08:50:46 -04:00
This means that when your application installs Angular, ***npm* doesn't automatically install
the packages listed in Angular's *peerDependencies* section**.
2016-05-26 08:50:46 -04:00
这意味着当我们的应用程序安装Angular时***npm*将不会自动安装列在Angular的*peerDependencies*区的那些包**
Fortunately, *npm* issues a warning (a) When any *peer dependencies* are missing, or (b)
When the application or any of its other dependencies
installs a different version of a *peer dependency*.
2016-09-25 14:50:45 -04:00
幸运的是,*npm*会在下列情况下给我们警告:(a) 当任何*平级依赖*缺失时 或(b) 当应用程序或它的任何其它依赖安装了与*平级依赖*不同版本的包时。
2016-05-26 08:50:46 -04:00
These warnings guard against accidental failures due to version mismatches.
They leave you in control of package and version resolution.
Merge remote-tracking branch 'origin/master' # Conflicts: # README.md # public/_includes/_scripts-include.jade # public/docs/_examples/homepage-hello-world/ts/index.1.html # public/docs/_examples/homepage-tabs/ts/index.1.html # public/docs/_examples/homepage-todo/ts/index.1.html # public/docs/_examples/systemjs.config.plunker.build.js # public/docs/_examples/systemjs.config.plunker.js # public/docs/js/latest/cookbook/ts-to-js.jade # public/docs/ts/latest/_data.json # public/docs/ts/latest/cookbook/component-communication.jade # public/docs/ts/latest/cookbook/component-relative-paths.jade # public/docs/ts/latest/glossary.jade # public/docs/ts/latest/guide/_data.json # public/docs/ts/latest/guide/architecture.jade # public/docs/ts/latest/guide/attribute-directives.jade # public/docs/ts/latest/guide/dependency-injection.jade # public/docs/ts/latest/guide/index.jade # public/docs/ts/latest/guide/lifecycle-hooks.jade # public/docs/ts/latest/guide/ngmodule.jade # public/docs/ts/latest/guide/npm-packages.jade # public/docs/ts/latest/guide/security.jade # public/docs/ts/latest/guide/server-communication.jade # public/docs/ts/latest/guide/template-syntax.jade # public/docs/ts/latest/guide/typescript-configuration.jade # public/docs/ts/latest/index.jade # public/docs/ts/latest/quickstart.jade # public/docs/ts/latest/tutorial/_data.json # public/docs/ts/latest/tutorial/toh-pt6.jade # public/features.jade # public/resources/js/directives/live-example.js # tools/plunker-builder/indexHtmlTranslator.js
2016-09-08 05:20:01 -04:00
这些警告可以避免因为版本不匹配而导致的意外错误。
2016-05-26 08:50:46 -04:00
它们让我们可以控制包和版本的解析过程。
It is your responsibility to list all *peer dependency* packages **among your own *devDependencies***.
我们的责任是,把所有*平级依赖*包都**列在我们自己的*devDependencies*中**。
2016-05-26 08:50:46 -04:00
.l-sub-section
:marked
#### The future of *peerDependencies*
2016-05-26 08:50:46 -04:00
#### *peerDependencies*的未来
The Angular polyfill dependencies are hard requirements. Currently, there is no way to make them optional.
2016-09-25 14:50:45 -04:00
Angular的填充库依赖只是一个给开发人员的建议或提示以便它们知道Angular期望用什么。
2016-05-26 08:50:46 -04:00
它们不应该像现在一样是硬需求,但目前我们也不知道该如何把它们设置为可选的。
However, there is an npm feature request for "optional peerDependencies," which would allow you to model this relationship better.
When this feature request is implemented, Angular will switch from *peerDependencies* to *optionalPeerDependencies* for all polyfills.
2016-05-26 08:50:46 -04:00
Merge remote-tracking branch 'origin/master' # Conflicts: # README.md # public/_includes/_scripts-include.jade # public/docs/_examples/homepage-hello-world/ts/index.1.html # public/docs/_examples/homepage-tabs/ts/index.1.html # public/docs/_examples/homepage-todo/ts/index.1.html # public/docs/_examples/systemjs.config.plunker.build.js # public/docs/_examples/systemjs.config.plunker.js # public/docs/js/latest/cookbook/ts-to-js.jade # public/docs/ts/latest/_data.json # public/docs/ts/latest/cookbook/component-communication.jade # public/docs/ts/latest/cookbook/component-relative-paths.jade # public/docs/ts/latest/glossary.jade # public/docs/ts/latest/guide/_data.json # public/docs/ts/latest/guide/architecture.jade # public/docs/ts/latest/guide/attribute-directives.jade # public/docs/ts/latest/guide/dependency-injection.jade # public/docs/ts/latest/guide/index.jade # public/docs/ts/latest/guide/lifecycle-hooks.jade # public/docs/ts/latest/guide/ngmodule.jade # public/docs/ts/latest/guide/npm-packages.jade # public/docs/ts/latest/guide/security.jade # public/docs/ts/latest/guide/server-communication.jade # public/docs/ts/latest/guide/template-syntax.jade # public/docs/ts/latest/guide/typescript-configuration.jade # public/docs/ts/latest/index.jade # public/docs/ts/latest/quickstart.jade # public/docs/ts/latest/tutorial/_data.json # public/docs/ts/latest/tutorial/toh-pt6.jade # public/features.jade # public/resources/js/directives/live-example.js # tools/plunker-builder/indexHtmlTranslator.js
2016-09-08 05:20:01 -04:00
不过有一个npm的新特性申请叫做“可选的peerDependencies”它将会允许我们更好的对这种关系建模。
2016-05-26 08:50:46 -04:00
一旦它被实现了Angular将把所有填充库从*peerDependencies*区切换到*optionalPeerDependencies*区。