node.js - 拷贝npm全局安装包到本地

标签 node.js npm

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

最佳答案

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

  • 大多数情况下全局包在终端中使用。
  • 本地包用于应用本身。

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

  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.)

关于node.js - 拷贝npm全局安装包到本地,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38277639/

相关文章:

javascript - 超测错误 : expected '[]' response body, 得到 '[""]'

node.js - 如何删除列表的内容而不仅仅是列表?如果x在y中,则删除x时也删除y

node.js - 如何在一个 git 存储库中管理 CDN 上的静态文件和另一台服务器上的业务逻辑?

debugging - 使用 dotnet cli watch 选项进行 Visual Studio 代码调试

node.js - npm install 导致无法读取未定义的属性 'name'

node.js - Mongoose 查询父级并包含带有引用的子级

node.js - Heroku 上找不到 js 文件

node.js - npm 不起作用,总是出现这个错误 -> 错误 : Cannot find module 'are-we-there-yet'

node.js - npm 安装错误 - 无法获取本地颁发者证书

node.js - 更新 Google Compute Engine 上的 Node/NPM?