如何从 git 存储库的子目录安装 Bower 组件?

How do you install a bower component from a subdirectory in a git repository?

我知道这可能违反惯例:

我正在尝试安装一个 bower.json 不在存储库顶层的 Bower 组件,因此效果如下:

bower install https://github.com/myrepo/my-components/tree/master/my-specific-component

但是 bower 回应如下:

bower not-cached    https://github.com/my-repo/my-components/tree/master/my-specific-component#*
bower resolve       https://github.com/my-repo/my-components/tree/master/my-specific-component#*
bower download      https://github.com/my-repo/my-components/tree/master/my-specific-component
bower EHTTP         Status code of 404

如何从这样的存储库的子目录安装组件?

我认为您不能从子文件夹安装 Bower。我认为惯例是 bower 检查 git 存储库的根目录(取决于您要求的提交),然后从那里安装组件和依赖项。 如果您查看 git 中托管的核心元素和论文元素,您会发现它们托管在不同的存储库

您可以使用 git 子模块将 git 包含在另一个 git 存储库中,这样您就可以在要使用 bower 安装时引用该子模块(虽然未测试)

如果您的 git 存储库是 public,那么 bower installs from https://github.com/org/repo/archive/tag.tar.gz。 如果您的 git 存储库是私有 bower,请执行给定 url.

的 git 克隆

因为 git 中没有 url 可以与 git clone 一起使用来克隆存储库的子目录,也没有 url 用于下载 [=21] =] 的子目录,bower 目前不支持从存储库的子目录安装。

我尝试了子模块,但无法正常工作。不幸的是,根据 Bower does not download git submodule (DojoX candidate plugin) 的讨论,它似乎不适用于 submoudle。根据@sheenathejunglegirl 的建议,我创建了一个存储库来演示使用存档文件的工作方法。当您需要的 public JS 文件尚未在 bower 存储库中注册或未托管在 public git 存储库中 bower.json.

时,这将很有用

只需使用简单的 bower.json 压缩 JS 文件,然后通过 github 的原始 URL 访问它。该示例可在 https://github.com/barryku/bower-repo-example 中找到。它可以与以下任何一种一起使用,

git install https://github.com/barryku/bower-repo-example.git
git install https://raw.github.com/barryku/bower-repo-example/master/my-bower-lib.0.0.1.zip

您可能需要调整 github 的原始文件 URL 它已更改。

我在存储库根目录下的子目录是 client/。我将 bower.json 移动到存储库根目录,并将 .bowerrc 放在根目录中,内容为:

{
   "directory" : "client/bower_components"
}

也许这对你来说是可以接受的。至少依赖项将安装在您的子目录下,但 bower.json 和 .bowerrc 必须驻留在根级别。