2016-06-23 27 views
4

在下面typings.json文件,ambientDependencies和定期依赖条件之间的区别是什么ambientDependencies(或globalDependencies)和定期的依赖之间的区别:什么是在分型

{ 
    "ambientDependencies": { 
    "es6-shim": "registry:dt/es6-shim#0.31.2+20160317120654", 
    "jasmine": "registry:dt/jasmine#2.2.0+20160412134438", 
    "jquery": "registry:dt/jquery#1.10.0+20160417213236" 
    }, 

“依赖”:{}, < ---这是做什么的?

} 

typings install <something> --save将保存到依赖关系,但是这是什么意思?

回答

5

想象你有两个依赖:

的package.json

{ 
    "dependencies": { 
     "a": "1.0", 
     "b": "2.0" 
    } 
} 

凡依赖关系树的样子:

|[email protected] 
|[email protected] 

在这种情况下,就没有什么区别将它们都作为globalDependenciesdependencies。 但是,当他们有自己的依赖关系时会出现问题。试想一下,你的依赖树是这个样子:

|[email protected] 
| |[email protected] 
| |[email protected] 
|[email protected] 

当您安装[email protected]作为一个全球性的依赖,这将剥夺引用[email protected][email protected],并会要求你安装这些依赖关系全局。它要求你的依赖关系树压扁到:

|[email protected] 
|[email protected] 
|[email protected] 
|[email protected] 

这工作正常[email protected],但现在你需要的b两个版本。 [email protected]取决于[email protected],但您的应用取决于[email protected]。你安装哪种类型的版本?如果安装[email protected],则[email protected]的类型定义可能会中断。如果您安装[email protected],您的应用类型可能会中断。这是面临的问题globalDependencies

当您使用类型构建类型定义并将其安装为常规依赖项时,它会将子依赖关系隐藏起来,而不会将它们暴露给您的应用程序。这意味着如果您将[email protected]安装为常规依赖项,则不会使用顶级[email protected]定义。它将使用自己的私人[email protected],而不会污染你的全局命名空间。有效的是,常规依赖保持你的依赖树结构,并且它们是接近定义的首选方式。问题是,并非所有库都将类型定义构建为常规依赖关系。理想情况下,随着人们编写更多定义,全局变量将被自然淘汰。

+0

简单的解释。干杯 – Belfield