如何进行npm安装以仅将依赖项保存到package.json? [英] How to npm install to only save dependency to package.json?

查看:846
本文介绍了如何进行npm安装以仅将依赖项保存到package.json?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在向package.json添加依赖关系,该依赖关系将用作虚拟机置备过程的一部分.因此,实际上我不需要在本地安装模块,因为供应商会在VM内为我完成安装.因此,有什么方法可以执行以下操作:

I'm adding dependencies to a package.json that will be used as part of a provisioning process for a virtual machine. As such, I don't actually need to install the modules locally since the provisioner will do that for me inside the VM. So is there any way to do the following:

npm install --save <module>

仅在 中创建package.json中模块最新版本的依赖项,而无需实际下载模块或创建node_modules文件夹?

So that it only creates a dependency for the latest version of the module in package.json without actually downloading the module or creating a node_modules folder?

--dry-run选项已关闭,因为它不会创建node_modules文件夹,但也不会写入package.json.

The --dry-run option is close, as it doesn't create a node_modules folder but it also doesn't write to package.json either.

目前,每次需要重新配置软件包之前,我都会手动执行以下操作:

For now, I'm manually doing the following each time I need to update packages before re-provisioning the VM:

rm -rf node_modules

造成这种情况的其他原因可能包括能够在低带宽情况下(例如网络共享)轻松构建package.json文件,在这种情况下,您知道最终将需要该模块,但又不想浪费带宽.

Other reasons for this might include being able to easily build a package.json file in low-bandwidth situations such as tethering, where you know you'll need the module eventually but don't want to spare the bandwidth.

推荐答案

无法使用我知道的npm来实现.

There is no way to do that with npm that I'm aware of.

有两个用于执行此操作的npm软件包;我从未使用过它们中的任何一个,但是它们可能值得一试:

There are two npm packages for doing this; I've never used either of them, but they might be worth a try:

  • https://www.npmjs.com/package/npm-add
  • https://www.npmjs.com/package/adddep

希望这会有所帮助!

这篇关于如何进行npm安装以仅将依赖项保存到package.json?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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