简体   繁体   English

package.json中指定的依赖项

[英]Dependencies specified in package.json

Let's say I have a client-side app (say an Ember application) 假设我有一个客户端应用程序(比如Ember应用程序)

I define my application's package.json with the various dependencies. 我用各种依赖项定义了我的应用程序的package.json。

    {
    name: "my-app",
    dependencies: {
       "dep1" : "1.0.0"
    },
    devDependencies: {
       "devDep1" : "1.0.0"
    }
    }

My question is 我的问题是

  1. Do I not have to worry about the dependencies which "dep1" itself would have? 我不必担心“dep1”本身会有什么依赖吗? Meaning not define those sub-dependencies in my package.json, coz they'll be taken care of in the package.json which "dep1" itself would define? 意思是不在我的package.json中定义那些子依赖项,因为它们将在package.json中处理,“dep1”本身将定义它?

  2. Any situations where we would define the dependencies in our own app..eg say our app uses "jquery" while even dep1 requires "jquery" ...Ideally, we would not define "jquery" in our own package.json in this case...But any use case where we might have to like different version required by our app...in this case, how would the overriding behavior work meaning what version gets considered? 在我们自己的应用程序中定义依赖项的任何情况......例如我们的应用程序使用“jquery”,而dep1甚至需要“jquery”...理想情况下,在这种情况下我们不会在我们自己的package.json中定义“jquery” ...但是我们可能不得不喜欢我们的应用所需的不同版本的任何用例......在这种情况下,覆盖行为将如何起作用意味着考虑哪个版本?

  3. Is this handled similarly across all package managers like npm, bower? 在所有包管理器(如npm,bower)中,这是否同样处理?

PS: Any additional info in an Ember engine environment would be useful as well (meaning when using a Parent app with child addon, etc.) PS:Ember引擎环境中的任何其他信息也很有用(意味着使用带有子插件的Parent应用程序等)

  • You don't have to worry about any dependent packages. 您不必担心任何依赖包。 They are read from the package's package.json that you have required and installed. 它们是从您需要和安装的软件包的package.json中读取的。
  • This is consistent across all package managers. 这在所有包管理器中都是一致的。

--- UPDATE --- ---更新---

npm dependencies are nested. npm依赖项是嵌套的。 This means that each package can have a separate version of the same package as a dependency. 这意味着每个包可以具有与依赖项相同的包的单独版本。 In your case, if a package requires "jquery" and you want to use a different version of "jquery", you can install any version as per your need and that will be the only version available to you and not any other version required by any dependency of your package. 在您的情况下,如果包需要“jquery”并且您想要使用不同版本的“jquery”,则可以根据需要安装任何版本,这将是您可用的唯一版本,而不是任何其他版本。你的包的任何依赖。

package.json or npm uses nested-dependencies which mean a dependency can have a own dependency on sub-dependency and so on. package.jsonnpm使用嵌套依赖项 ,这意味着依赖项可以对子依赖项具有自己的依赖性,依此类推。 npm will resolve those dependency by itself. npm将自己解决这些依赖。 This allows different modules to have different version of same dependency. 这允许不同的模块具有相同依赖性的不同版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM