简体   繁体   English

npm如何知道您处于开发/开发模式?

[英]How does npm know you're in dev/developing mode?

有人可以向我解释--save-dev的含义,以及它如何影响发行以及NPM如何知道您要做什么吗?

--save-dev is useful for dependencies such as unit testing libraries. --save-dev对于诸如单元测试库之类的依赖项很有用。 These dependencies are not required by the application to run in production; 应用程序在生产环境中运行时并不需要这些依赖关系。 therefore if you published your package, consumers of your package would not get these dev dependencies in their node_modules folder. 因此,如果发布了程序包,则程序包的使用者将不会在它们的node_modules文件夹中获得这些dev依赖项。

NPM doesn't necessarily know that your in dev mode, it's just a package manager that allows you to install packages into your working directory and publish your own package from said directory. NPM不一定知道您处于开发模式,它只是一个软件包管理器,它允许您将软件包安装到您的工作目录中并从该目录发布您自己的软件包。

First , see the answer to this question, What's the difference between dependencies, devDependencies and peerDependencies . 首先 ,查看此问题的答案, dependency,devDependencies和peerDependencies之间有什么区别

That will explain a TON. 这将解释一个TON。

Second , npm will install devDependencies by default unless one of two things is true, in which case devDependencies will be skipped. 其次 ,除非满足以下两个条件之一,否则npm将默认安装devDependencies,在这种情况下,将跳过devDependencies。 These things are: 这些是:

  1. You explicitly tell npm it's production with npm install --production 您通过npm install --production明确告诉npm它是生产环境
  2. You set an environment variable that npm checks, NODE_ENVIRONMENT=production 您设置了一个由npm检查的环境变量, NODE_ENVIRONMENT=production

In general, if you are distributing to something like Heroku, they will have the production flag set and your devDependencies will not be installed. 通常,如果您要分发给Heroku之类的东西,则将设置生产标志,并且不会安装devDependencies。 So only install things with the --save-dev or -D flag (both do the same thing) if it is a module used for development, such as tests/mocks/scaffolding/etc. 因此,如果它是用于开发的模块,则仅安装带有--save-dev-D标志的东西(两者都做相同的事情),例如test / mocks / scaffolding / etc。

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

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