在单个Git存储库中存储多个NPM库 [英] Storing multiple NPM libraries in single Git repo
问题描述
我们可以像这样在Github上引用NPM deps:
We can reference NPM deps on Github like so:
"dependencies":{
"foo":"github.com/org/root#commit"
}
但是我有一个包含多个NPM库的Git存储库,如下所示:
But I have a Git repo with multiple NPM libraries in it, like so:
root/
nodejs/
foo/
package.json
bar/
package.json
是否可以直接从此Github存储库中安装foo?像这样吗?
is there a way to install foo from this Github repo directly? Something like this?
"dependencies":{
"foo":"github.com/org/root/nodejs/foo#commit"
}
我尝试使用该网址进行安装,但没有成功,出现了此错误:
I tried installing using that url, and it didn't work, I got this error:
npm ERR! code ENOPACKAGEJSON
npm ERR! package.json Non-registry package missing package.json: https://raw.githubusercontent.com/org/root/master/nodejs/foo/package.json.
npm ERR! package.json npm can't find a package.json file in your current directory.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/oleg/.npm/_logs/2018-12-05T09_15_28_666Z-debug.log
我也尝试过像这样使用raw.githubusercontent.com:
I also tried using raw.githubusercontent.com like so:
"dependencies":{
"foo":"raw.githubusercontent.com/org/root/nodejs/foo#commit"
}
我遇到了同样的错误.当然一定有可能做到这一点吗?
And I got the same error. Surely this must be possible somehow?
推荐答案
好的,所以一种解决方案是使用tarball.因此,您可以使用以下命令:
Ok so one solution is to use tarballs. So you can use this command:
npm i -S 'https://raw.githubusercontent.com/org/root/master/nodejs/foo/foo-0.0.1001.tgz'
它工作了..我在package.json中得到了它:
it worked..and I get this in package.json:
"dependencies": {
"foo": "https://raw.githubusercontent.com/org/root/master/nodejs/foo/foo-0.0.1001.tgz"
}
基本上,您所需要做的就是使用指向tarball的url进行npm install.
basically all you need to do is npm install with a url that points to a tarball.
这篇关于在单个Git存储库中存储多个NPM库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!