简体   繁体   English

npm install是否排除dev依赖项?

[英]Does npm install exclude dev dependencies?

When I am in a Node.js project and run npm install , npm installs both, dependencies and dev dependencies. 当我在Node.js项目中并运行npm install ,npm会同时安装依赖项和dev依赖项。 If I do not want to install the dev dependencies, I can run npm install --production . 如果我不想安装dev依赖项,我可以运行npm install --production

Question 1: If I do not provide --production : Are the dependencies' dev dependencies installed, too, or only their actual dependencies? 问题1:如果我提供--production :是否安装了依赖项的dev依赖项,或者只安装了它们的实际依赖项?


Now, what if I am in a Node.js project and install a new dependency, something such as: 现在,如果我在Node.js项目中并安装新的依赖项,例如:

npm install foo

This installs foo 's dependencies, of course. 当然,这会安装foo的依赖项。

Question 2: But what about its dev dependencies? 问题2:但它的开发依赖关系呢? Are they installed, too, or are they skipped? 它们也是安装的,还是被忽略了?

Answers to your questions: 您的问题的答案:

  1. Yes dev dependencies will be installed in npm install only way it wont install dev dependencies is when NODE_ENV is set to production 是的,将在npm install安装dev依赖项,只有在NODE_ENV设置为productionNODE_ENV安装dev依赖项
  2. No dev dependencies of your external modules won't be installed see here 此处不会安装外部模块的dev依赖项

When you run npm install by default both dependencies and devDependency dependencies are also installed. 默认运行npm install时,还会安装依赖项和devDependency依赖项。 Because if once is going to develop a package, we would download it eg from git and go to root folder and run. 因为如果要开发一个包,我们会从git下载它,然后转到root文件夹并运行。

npm install 

so you would expect to have devDependencies to. 所以你希望有devDependencies。

npm install "$package"

doesn't install the devDependencies by default. 默认情况下不安装devDependencies。 But if you really want to install development packages in that case, you can set the dev config option to true: 但是如果你真的想在这种情况下安装开发包,你可以将dev config选项设置为true:

npm install "$package" --dev

Node applications use multiple methods to maintain dependency versioning up to date but there are multiple dependency types that need to be considered. 节点应用程序使用多种方法来维护最新的依赖项版本,但需要考虑多种依赖项类型。 Dependencies are found in a node application's root directory within the package.json file. 可以在package.json文件中的节点应用程序的根目录中找到依赖项。 I will go through the different dependency types and list some defining features or characteristics: 我将介绍不同的依赖类型并列出一些定义的特性或特征:

Dependencies: These are specified in a simple object that maps a package name to a version range. 依赖关系:这些是在将包名称映射到版本范围的简单对象中指定的。 The version range is a string which has one or more space-separated descriptors. 版本范围是一个字符串,其中包含一个或多个以空格分隔的描述符。 Dependencies can also be identified with a tarball or git URL. 也可以使用tarball或git URL识别依赖关系。

npm install from a directory that contains package.json npm install $package on any other directory dependencies are required to run Installed transitively: if A requires B, and B requires C. then C gets installed, otherwise B could not work, and neither would A. devDependencies: If someone is planning on downloading and using module in their program, then they probably don't want or need to download and build the external test or documentation framework that you use. npm从包含package.json的目录安装npm install $ package在任何其他目录上依赖需要运行以传递方式安装:如果A需要B,B需要C.然后C安装,否则B无法工作,也不会A. devDependencies:如果有人计划在他们的程序中下载和使用模块,那么他们可能不希望或不需要下载和构建您使用的外部测试或文档框架。 In this case it's best to map these additional items in a devDependencies object, which is not installed when the user is installing the package unless specifically passing in --dev. 在这种情况下,最好将这些附加项映射到devDependencies对象中,除非特意传入--dev,否则在用户安装包时不会安装该对象。 These are typically installed when doing a traditional npm install from the root of the package. 这些通常是在从包的根目录进行传统的npm安装时安装的。

npm install on a directory that contains package.json, unless the developer passes the --production flag. npm install在包含package.json的目录上,除非开发人员传递--production标志。
not installed on npm install "$package" on any other directory, unless you give it the --dev option Are not installed transitively Other Dependency types: These are less commonly used but may serve a purpose. 没有安装在任何其他目录上的npm安装“$ package”,除非你给它--dev选项没有传递的其他依赖类型:这些不太常用但可能有用。

peerDependencies optionalDependencies peerDependencies optionalDependencies

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

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