我正在开发一个自定义 npm 模块,并且它有一个 GitHub 存储库。我还在开发一个使用自定义模块的项目。当处理较大的项目时,使用它是很好的npm link
这样我就可以对模块进行更改并立即在主项目中看到它们。
To deploy to staging or production, I use shrinkwrap and shrinkpack so I can do an npm install
after every deploy (some of the dependencies need binaries, and dev systems aren't the same as production systems, so they do need to be installed and not just kept in source control). Edit: I'm crossing this out as the answer below technically solves my issue, even though it doesn't solve for this particular point, but that wasn't as important as the rest of it.
当然,由于该模块链接到我的主项目并且未在中列出package.json
,部署和安装完全错过了它。我可以继续将其列出package.json
并让它指向适当的 GitHub 存储库,但是每次我需要在主项目中测试更改时,我都必须提交并推送这些更改,然后更新主项目,终止并重新启动应用程序...这将很快就会感到厌倦。
我想我需要类似于“devDependency”的相反内容;我能得到的东西not在 dev 上安装模块,但是do执行时从 GitHub 安装它npm install
上演或制作。除了记得手动更改之外package.json
每次我需要来回时,有没有更好的方法来做到这一点?
您可以在 package.json 文件中指定 github 存储库作为要安装的包:
{
dependencies: {
"my-library": "githubusername/my-library"
}
}
这将在您的生产环境中起作用。
在您的开发环境中,使用“npm link”。
从“my-library”文件夹中运行npm link
直接地。这将告诉本地机器上的 npm “my-library”可以作为链接使用。
现在,在使用“my-library”的项目中,运行npm link my-library
。这将创建一个指向“my-library”本地开发版本的符号链接,允许您更改该存储库中的代码并使其在需要它的其他项目中工作。
一旦您准备好推送到生产环境,请将“my-library”推送到您的 github 存储库,然后您可以像平常一样在服务器上进行 npm install。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)