如果我全局安装了一个 npm 包,并且我想在某个项目中本地安装相同的包,npm 是再次下载该包还是从全局安装文件夹中复制它?如果没有,是否有办法让它做到这一点?
最佳答案
不建议将文件从全局复制到本地。两个地方都安装包是很正常的。
- 大多数情况下全局包在终端中使用。
- 本地包用于应用本身。
你也可以使用 npm link 来符号链接(symbolic link)一个全局包
- Install it in both places. Seriously, are you that short on disk space? It’s fine, really. They’re tiny JavaScript programs.
- 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/