如何在没有自己的注册表的情况下安装私有NPM模块?

本文翻译自:How to install a private NPM module without my own registry?

I've taken some shared code and put it in an NPM module, one I don't want to upload to the central registry. 我已经采用了一些共享代码并将其放入NPM模块中,我不想将其上传到中央注册表。 The question is, how do I install it from other projects? 问题是,如何从其他项目安装它?

The obvious way is probably to set up my own NPM registry, but according to the documentation, that involves a lot of hassle. 显而易见的方法可能是建立我自己的NPM注册表,但根据文档,这涉及很多麻烦。

Can I just install an NPM module that sits on the local filesystem, or perhaps even from git? 我可以只安装一个位于本地文件系统上的NPM模块,甚至可以安装git吗?

npm install --from-git git@server:project

#1楼

参考:https://stackoom.com/question/hZx8/如何在没有自己的注册表的情况下安装私有NPM模块


#2楼

cd somedir
npm install .

or 要么

npm install path/to/somedir

somedir must contain the package.json inside it. somedir必须包含package.json

It knows about git too: 它也知道git:

npm install git://github.com/visionmedia/express.git

#3楼

In your private npm modules add 在你的私人npm模块中添加

"private": true 

to your package.json 到你的package.json

Then to reference the private module in another module, use this in your package.json 然后引用另一个模块中的私有模块,在package.json中使用它

{
    "name": "myapp",
    "dependencies": {
        "private-repo": "git+ssh://[email protected]:myaccount/myprivate.git#v1.0.0",
    }
}

#4楼

Can I just install an NPM package that sits on the local filesystem, or perhaps even from git? 我可以只安装一个位于本地文件系统上的NPM包,或者甚至可以安装git吗?

Yes you can! 是的你可以! From the docs https://docs.npmjs.com/cli/install 来自docs https://docs.npmjs.com/cli/install

A package is: 包裹是:

  • a) a folder containing a program described by a package.json file a)包含package.json文件描述的程序的文件夹
  • b) a gzipped tarball containing (a) b)包含(a)的压缩的tarball
  • c) a url that resolves to (b) c)解析为(b)的网址
  • d) a <name>@<version> that is published on the registry with (c) d)在注册表中发布的<name>@<version> (c)
  • e) a <name>@<tag> that points to (d) e)指向(d)的<name>@<tag>
  • f) a <name> that has a "latest" tag satisfying (e) f)具有满足(e)的“最新”标签的<name>
  • g) a <git remote url> that resolves to (b) g)解析为(b)的<git remote url>

Isn't npm brilliant? 是不是很棒?


#5楼

I had this same problem, and after some searching around, I found Reggie ( https://github.com/mbrevoort/node-reggie ). 我遇到了同样的问题,经过一番搜索后,我找到了Reggie( https://github.com/mbrevoort/node-reggie )。 It looks pretty solid. 它看起来很稳固。 It allows for lightweight publishing of NPM modules to private servers. 它允许将NPM模块轻量级发布到私有服务器。 Not perfect (no authentication upon installation), and it's still really young, but I tested it locally, and it seems to do what it says it should do. 不完美(安装时没有身份验证),它仍然非常年轻,但我在本地测试它,它似乎做它应该做的事情。

That is... (and this just from their docs) 那是......(这只是来自他们的文档)

npm install -g reggie
reggie-server -d ~/.reggie

then cd into your module directory and... 然后进入你的模块目录并...

reggie -u http://<host:port> publish 
reggie -u http://127.0.0.1:8080 publish 

finally, you can install packages from reggie just by using that url either in a direct npm install command, or from within a package.json... like so 最后,您可以通过直接npm install命令或者在package.json中使用该URL来安装来自reggie的软件包...就像这样

npm install http://<host:port>/package/<name>/<version>
npm install http://<host:port>/package/foo/1.0.0

or.. 要么..

dependencies: {
    "foo": "http://<host:port>/package/foo/1.0.0"
}

#6楼

FWIW: I had problems with all of these answers when dealing with a private organization repository. FWIW:在处理私有组织存储库时,我遇到了所有这些问题的问题。

The following worked for me: 以下对我有用:

npm install -S "git+https://[email protected]/orgname/repositoryname.git"

For example: 例如:

npm install -S "git+https://[email protected]/netflix/private-repository.git"

I'm not entirely sure why the other answers didn't work for me in this one case, because they're what I tried first before I hit Google and found this answer. 在这一个案例中,我不完全确定为什么其他答案对我不起作用,因为它们是我在点击谷歌并找到答案之前首先尝试的。 And the other answers are what I've done in the past. 其他答案就是我过去所做的。

Hopefully this helps someone else. 希望这有助于其他人。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章