【问题标题】:How do you install a bower component from a subdirectory in a git repository?如何从 git 存储库的子目录中安装 bower 组件?
【发布时间】:2015-03-11 15:41:22
【问题描述】:

我知道这可能违反惯例:

我正在尝试安装一个 bower 组件,它的 bower.json 不位于存储库的顶层,所以效果如下:

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

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

【问题讨论】:

    标签: github polymer bower


    【解决方案1】:

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

    您可能可以使用 git submodule 将 git 包含在另一个 git repo 中,以便在您想使用 bower 安装时引用子模块(虽然未测试)

    【讨论】:

      【解决方案2】:

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

      由于 git 中没有可用于 git clone 克隆存储库子目录的 url,也没有用于下载子目录 tar 的 url,因此 bower 目前不支持从存储库的子目录安装。

      【讨论】:

        【解决方案3】:

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

        只需使用简单的 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,因为它已更改。

        【讨论】:

          【解决方案4】:

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

          {
             "directory" : "client/bower_components"
          }
          

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

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2015-05-06
            • 2014-05-07
            • 2016-04-03
            • 1970-01-01
            • 2016-09-22
            • 2011-09-12
            • 2019-08-24
            相关资源
            最近更新 更多