安装 npm 本地包依赖 [英] Install npm local package dependencies

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

问题描述

我从本地路径安装了一个 npm 依赖项,而该路径又具有自己的一些依赖项.据我了解,在这种情况下,npm 只是复制 node_modules 下本地文件夹的内容.有没有办法让它在复制之前在包文件夹上运行 npm install ?

I have a npm dependency installed from a local path, which in turn has a few dependencies of its own. As I understand it, in this case npm just copies the contents of the local folder under node_modules. Is there any way to make it run npm install on the package folder before copying it?

推荐答案

npm install/path/to/foo 只需从指定路径复制到本地包的 node_modules文件夹.如果这就是从本地路径安装"的意思,那么如果您想确保 npm updatenpm install 在您的包将 (a) 自动从该路径获取最新代码,以及 (b) 在该路径上更新/安装包的依赖项.

npm install /path/to/foo simply copies from the specified path into your local package's node_modules folder. If this is what you meant by "installed from a local path", then that was the wrong thing to do if you want to make sure that npm update and npm install on your package would (a) automatically get the latest code from that path and (b) update/install the dependencies of the package at that path.

为了完成 (a) 和 (b),您可以将该本地依赖添加到您的 package.jsondependenciesdevDependencies(自 2.0 起由 npm 支持).例如:

To accomplish (a) and (b), you can add that local dependency to your package.json's dependencies or devDependencies (supported by npm since 2.0). For example:

"dependencies": {
  "foo": "file:/path/to/foo"
}

执行上述操作后,npm updatenpm install 会以与任何其他依赖项相同的方式处理该本地依赖项.

After doing the above, npm update or npm install will treat that local dependency in the same way as any other dependency.

这篇关于安装 npm 本地包依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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