npm install --save,不保存有什么用 [英] npm install --save, what is the use of not saving

查看:119
本文介绍了npm install --save,不保存有什么用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解 npm install somethingnpm install something --save 之间的区别(对于任何想知道的人,第一个只会安装依赖项,而后者会安装依赖项并将其添加到您的 package.json 中).

I understand the differences between npm install something and npm install something --save (for anyone wondering, the first one will install the dependency only while the latter will install the dependency and add it to your package.json).

但是我不明白为什么首先有一个 --save 选项.换句话说,您为什么要安装依赖项而不将其添加到您的 package.json 文件中?为什么 --save 选项不是默认的?

However I do not understand why there is a --save option in the first place. In other words, why would you ever want to install a dependency without adding it to your package.json file? Why is the --save option not default?

许多网站/npm 模块/SaaS 建议使用 npm install something 安装他们的模块(例如,newrelic 就是其中之一),我是否遗漏了什么?

A lot of websites/npm modules/SaaS suggest installing their module using npm install something (newrelic is one of them for instance), am I missing something?

编辑:从 NPM 5 开始, --save 现在默认开启.

Edit: Starting from NPM 5, --save is now on by default.

推荐答案

  1. 您可能会遇到这样的情况,例如您需要安装一些模块,而无需向 package.json 文件添加依赖项,例如.您只是想尝试一些模块,但不确定您是否真的会在生产中或部署时使用该模块,因此将模块依赖项添加到 package.json 中,只需在不使用代码>--保存.这就是不存在 --savenpm install 存在的原因.

  1. You would have a scenario such as you need some module to install without adding dependency to package.json file, for ex. you just want to try some module, and not sure you would be really using that module in production or while deploying, so instead adding the module dependency to package.json, just give it a try without using --save. this is why npm install without --save exists.

但是对于您的大多数模块,您可能需要使用 --save,例如.npm install express --save,在这种情况下,您肯定知道要为您的应用程序使用 express.

But For most of your modules you might require using --save, for ex. npm install express --save, in this case you surely know that you are going to use express for you application.

另一种情况,如果不使用 --save,将是 npm install heapdumpnpm install nodemon,我将使用它来测试我的应用程序性能,但不会在 package.json 中添加依赖项 :)

The other scenario, for not using --save, would be, npm install heapdump or npm install nodemon, I would use it for testing my apps performance, but not add a dependency in the package.json :)

此外,正如@surajck 在下面的评论中所说:当您进行全局安装时,在这种情况下,使用 --save 添加依赖项到 package.json 没有意义.

Also, As @surajck said in comment below: when you are doing global installs, in that case adding dependencies using --save, to the package.json would not make sense.

这篇关于npm install --save,不保存有什么用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆