将 npm 全局安装包复制到本地 [英] copy npm global installed package to local

查看:403
本文介绍了将 npm 全局安装包复制到本地的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个全局安装的 npm 包,并且我想在某个项目中本地安装相同的包,npm 是再次下载该包还是从全局安装文件夹中复制它?如果没有,有没有办法让它做到这一点?

解决方案

不建议将文件从全局复制到本地.在两个地方都安装了包是很正常的.

  • 大多数情况下全局包用于终端.
  • 本地包用于应用程序本身.

你也可以使用 npm link 来符号链接一个全局包

<块引用>

  1. 在两个地方安装它.说真的,你是不是磁盘不够用空间?没关系,真的.它们是微型 JavaScript 程序.
  2. 安装它全局,然后 npm link coffee-scriptnpm link express(如果你在一个支持符号链接的平台上.)那么你只需要更新全局副本以更新所有符号链接.

我认为第一个选项是最好的.简单、清晰、明确.这如果您要重用相同的库,则第二个非常方便一堆不同的项目.(更多关于 npm 链接 在未来分期付款.)

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? 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

  1. Install it in both places. Seriously, are you that short on disk space? It’s fine, really. They’re tiny JavaScript programs.
  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.

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 全局安装包复制到本地的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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