简体   繁体   中英

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

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

--save-dev is useful for dependencies such as unit testing libraries. 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.

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.

First , see the answer to this question, What's the difference between dependencies, devDependencies and peerDependencies .

That will explain a TON.

Second , npm will install devDependencies by default unless one of two things is true, in which case devDependencies will be skipped. These things are:

  1. You explicitly tell npm it's production with npm install --production
  2. You set an environment variable that npm checks, 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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