给npm install添加本地项目依赖

4

如何在npm的package.json文件中添加本地项目依赖的正确语法是什么?

我在C:\projects\MyApp中本地拥有git项目。

我想通过npm install获取此项目。我尝试了以下方式:

"dependencies": {
  .....
  "my-app": "file://../projects/MyApp/MyApp.git"
  .....
 }

但是出现了错误。
Could not install ....

有什么建议吗?


以上问题中有一个拼写错误:'dependencioes'。 - mit
更正了打字错误。 - αƞjiβ
3个回答

8

终于让它工作了。

"my-app": "../projects/MyApp"

只要你知道了,它就变得简单了。


2
本地依赖必须是您文件系统上的目录。
Alternately there is npm-link.
文档摘录:

Package linking is a two-step process.

First, npm link in a package folder will create a globally-installed symbolic link from prefix/package-name to the current folder (see npm-config for the value of prefix).

Next, in some other location, npm link package-name will create a symlink from the local node_modules folder to the global symlink.

Example:

cd ~/projects/node-redis    # go into the package directory
npm link                    # creates global link
cd ~/projects/node-bloggy   # go into some other package directory.
npm link redis              # link-install the package

0

啊,我误解了你的问题,因为我没有关注那句话:“我在C:\projects\MyApp本地有git项目”。 - Silerra

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接