【问题标题】:How to specify npm dependency as github subfolder url?如何将 npm 依赖项指定为 github 子文件夹 url?
【发布时间】:2017-02-02 10:29:43
【问题描述】:

我的 git 仓库:

README.md
packages
  common
    package.json
  main
    package.json

如何将main package.json 中的common 依赖指定为github 子文件夹url?

这不起作用"common": "git://github.com/<user>/<project>/packages/common.git"

【问题讨论】:

    标签: git github npm


    【解决方案1】:

    您正在寻找的是git submodules。简而言之,您告诉 get 在以下 repo 中查找此文件夹。

    为此,请执行以下命令:

    git submodule add git://github.com/<user>/<project>/packages/common.git packages/common
    

    请注意,在克隆 repo 时,您需要递归克隆它才能下载子模块:

    git clone --recursive <your-git-url>
    

    【讨论】:

    • 当我从本地目录 /packages/common 执行 git remote add origin https://github.com/&lt;user&gt;/&lt;project&gt;/packages/common.git 然后 git push -u origin master 我收到错误 fatal: repository 'https://github.com/&lt;user&gt;/&lt;project&gt;/packages/common.git/' not found
    • git remote add is different than git submodule add what you do by git remote add origin .... is replace your original remote by this one, now you are trying to push to another repo.
    【解决方案2】:

    NPM 似乎不支持此功能,并且 NPM 团队似乎对支持此功能没有兴趣。

    https://github.com/npm/npm/issues/2974

    【讨论】:

    • 很不幸,这不被支持......所以我需要为每个包创建一个存储库......
    猜你喜欢
    • 2014-11-12
    • 2018-12-07
    • 1970-01-01
    • 2019-11-15
    • 2020-07-21
    • 1970-01-01
    • 2012-11-10
    • 2016-12-16
    • 1970-01-01
    相关资源
    最近更新 更多