简体   繁体   English

将npm全局安装包复制到本地

[英]copy npm global installed package to local

If I have a npm package installed globally, and I want to install the same package locally in some project, does npm download the package again or copy it from the global install folder? 如果我全局安装了npm软件包,并且我想在某个项目中本地安装相同的软件包,那么npm是否会再次下载软件包或从全局安装文件夹中复制它? If not, is there a way to make it do that? 如果没有,有没有办法让它做到这一点?

It is not recommended to copy files from global to local. 建议不要将文件从全局复制到本地。 It is pretty normal to have package installed in both places. 在两个地方都安装了包是很正常的。

  • Global package in most of the cases is used in terminal. 大多数情况下的全局包用于终端。
  • Local package is used in application itself. 本地包用于应用程序本身。

Also you can use npm link to symlink a global package 您还可以使用npm链接来对全局包进行符号链接

  1. Install it in both places. 在两个地方安装它。 Seriously, are you that short on disk space? 说真的,你的磁盘空间不足吗? It's fine, really. 这很好,真的。 They're tiny JavaScript programs. 它们是一个很小的JavaScript程序。
  2. Install it globally, and then npm link coffee-script or npm link express (if you're on a platform that supports symbolic links.) Then you only need to update the global copy to update all the symlinks as well. 全局安装,然后npm link coffee-scriptnpm link express (如果你在支持符号链接的平台上。)那么你只需要更新全局副本来更新所有的符号链接。

The first option is the best in my opinion. 在我看来,第一个选项是最好的。 Simple, clear, explicit. 简单,清晰,明确。 The second is really handy if you are going to re-use the same library in a bunch of different projects. 如果要在一堆不同的项目中重用相同的库,第二个非常方便。 (More on npm link in a future installment.) (有关未来分期中npm链接的更多信息。)

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

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