如何在 Bower 中注册本地 git 包? [英] How to register a local git package in Bower?

查看:33
本文介绍了如何在 Bower 中注册本地 git 包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 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 上),该存储库是 registerd,带有名称和 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 registerd 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 registering 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 包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆