如何在沒有自己的註冊表的情況下安裝私有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. 希望這有助於其他人。

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