`npm link x` 和 `npm install/path/to/x` 之间的区别 [英] Difference between `npm link x` and `npm install /path/to/x`
问题描述
我以为我明白了
npm link x
和
npm install /local/path/to/x
最初我认为前者创建了一个指向 x 的符号链接,而后者在您的项目中安装了一个单独的 x 副本,而不是对其进行符号链接.
originally I thought the former created a symlink to x, whereas the latter installed a separate copy of x in your project, instead of symlinking it.
但是,最近发现我原来的印象是错误的,而且它们似乎都使用了符号链接 - 那么两者之间有什么区别吗?
However, I recently noticed that my original impression was wrong, and they both seem to use symlinks - so is there a difference between the two and what is it?
推荐答案
Alex Mills 的一篇关于 Medium 的文章 将其展示出来.
它说 npm link x
和 npm install/local/path/to/x
之间的区别是:
It says the difference between npm link x
and npm install /local/path/to/x
are:
最大的不同在于
npm install/local/path/x
运行 preinstall/postinstall 钩子,但npm link x
不会.
The big difference is that
npm install /local/path/x
will run the preinstall/postinstall hooks, butnpm link x
will not.
npm link
使用全局 NPM 空间,npm install/local/path/x
没有.npm link 创建一个指向 x 的符号链接在全局空间中,然后当您从y,它创建的符号链接不是直接指向 x,而是指向全局符号链接.这是一个重要的区别,如果你是使用不同的全局 node.js 版本,例如 NVM.
npm link
uses the global NPM space, npm install /local/path/x
does not. npm link creates a symlink to x
in the global space, and then when you call npm link x from
y, it creates a symlink not directly to x, but rather to
the global symlink. This is an important differences if you are
using different global node.js versions, e.g., NVM.
npm install/absolute/path/x
将改变 package.json,npm link x
没有.
npm install /absolute/path/x
will alter package.json, npm link x
does not.
要获取新的本地副本而不是符号链接,请使用 npm pack
,如下所示:
To get a fresh local copy instead of a symlink, use npm pack
, like so:
tgz="$PWD/$(npm pack)"
cd <other project>
npm install "$tgz"
您也可以使用 cp/rsync,但这不会运行安装挂钩或将可执行文件放在 node_modules/.bin
中...那会起作用.
You could also use cp/rsync, but that wouldn't run install hooks or put the executables in node_modules/.bin
...that will work.
这篇关于`npm link x` 和 `npm install/path/to/x` 之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!