問題描述
如何在 bower 中注冊本地 git 包?
How can I register a local git package in bower?
我現在的component.json如下
My current component.json is as follows
{
"name": "myproject",
"version": "1.0.0",
"dependencies": {
"jquery": "1.8.0",
"twitter/bootstrap": "2.1.1"
}
}
不過,我還想添加一個我在 C:/mypackage
創建的包,這是一個帶有版本標記的 git 存儲庫.當我執行 bower install --save C:/mypackage
時,它會正確地將其添加到項目中,但不會將其添加到我的 component.json 中.
However I also would like to add a package I have created at C:/mypackage
which is a git repository with versions tagged.
When I do bower install --save C:/mypackage
it properly adds it to project but it doesn't add it to my component.json.
我正在嘗試 bower register mypackage C:/mypackage
但它一直給我
I am trying bower register mypackage C:/mypackage
but it keeps giving me
bower error Incorrect format
我做錯了什么?
推薦答案
選項 1:Public Bower 注冊
Bower 的構建主要是為了以非自以為是"的方式共享公共(客戶端)代碼.那么,主要用例是擁有一個可公開訪問的存儲庫(在 GitHub 上),該存儲庫是 register
d,帶有名稱和 git 存儲庫 url.我自己就是這樣做的:
Option 1: Public Bower registration
Bower is built mostly to share public (client-side) code in a "non-opinionated" manner. The primary use case, then, is to have a publicly accessible repository (on GitHub) that is register
d with a name and git repository url. I just did this myself:
bower register linksoup git://github.com/automatonic/linksoup
這只是告訴 Bower 服務器,當您 install linksoup
去獲取 git://github.com/automatonic/linksoup
存儲庫中的代碼時,并放到本地項目的component
目錄下.
This is just telling the bower server that when you install linksoup
to go and grab the code at the git://github.com/automatonic/linksoup
repository, and put it in the local project's component
directory.
如果這是您想要做的,那么只需在 github/etc. 上設置一個存儲庫,將您的代碼推送到那里,然后使用生成的存儲庫信息 register
.
If this is what you want to do, then just set up a repository on github/etc., push your code there, and then register
with the resulting repository info.
不將代碼發布到可公開訪問的存儲庫的原因有很多.它可能不是開源的,等等.如果您的 mypackage
代碼不打算公開,那么您可能不應該在公共涼亭服務器上注冊
.. 此外,即使您可以注冊
一個本地目錄,它也只能在您的機器上運行...這違背了通過 bower 共享代碼的目的.
There are many reasons not to post your code at a publicly accessible repository. It may not be open source, etc. if your mypackage
code is not meant to be public, then you should probably not be register
ing it on the public bower server... Further, even if you could register
a local directory, it would only work on your machine...which defeats the purpose of sharing the code via bower.
如果您只想讓 bower 管理本地的私有依賴項,那么我將重復 blockhead's解決方案:
If you just want to have bower manage a local, private dependency, then I am going to riff off of blockhead's solution:
{
"name": "myproject",
"version": "1.0.0",
"dependencies": {
"jquery": "1.8.0",
"twitter/bootstrap": "2.1.1",
"mypackage": "file:///path/to/mypackage/.git"
}
}
這只是說 myproject
需要 mypackage
,并使用 git clone 來檢索它.我的猜測是這可以使用 git 可以理解的任何東西(包括本地存儲庫).但是您應該注意,這可能會給其他任何處理此代碼而無法訪問您的本地路徑的人帶來問題.
This is just saying that myproject
needs mypackage
, and to use git clone to retrieve it. My guess is that this can use anything git can understand (including local repositories). But you should note that this may run into problems for anyone else working on this code that cannot access your local path.
在我看來,您可能已經假設 bower register
是本地操作(告訴 bower 如何通過某種本地注冊表查找依賴項).據我所知,這只是遠程和公共注冊,這就是不支持的原因.
It looks to me as if you may have assumed that bower register
was a local operation (telling bower how to find a dependency via some sort of local registry). As far as I can tell, this is only a remote and public registration, which is why this is unsupported.
您可能還在尋找一種方法來執行 與 npm 的鏈接操作.也就是說,在依賴模塊上工作而不總是讓您的開發周期包含發布.
You may also be looking for a way to do something like a link operation with npm. That is, work on a dependency module without always having your dev cycle include a publish.
詳細說明有多少人參與其中以及您試圖完成的工作將有助于獲得更有針對性的答案.
A little detail about how many people are involved and what you were trying to accomplish would facilitate a more targeted answer.
這篇關于如何在 Bower 中注冊本地 git 包?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!