npm从github repo子文件夹安装包

Cer*_*dan 31 git github npm

当包位于子文件夹中时,是否可以从github安装npm包?

例如,我们有Microsoft BotBuilder存储库:https: //github.com/Microsoft/BotBuilder

但我需要在子文件夹"Node/core /"中安装软件包:https: //github.com/Microsoft/BotBuilder/tree/master/Node/core/

那么如何用npm安装呢?

Sha*_*aee 31

如果包源托管在 GitHub 上,您可以像这样使用GitPkg :

# using npm:
npm install https://gitpkg.now.sh/<user>/<project>/<subdir>?<commit-ish>
# using yarn:
yarn add https://gitpkg.now.sh/<user>/<project>/<subdir>?<commit-ish>
Run Code Online (Sandbox Code Playgroud)

对于您的特定情况,URL 将是这样的:

https://gitpkg.now.sh/Microsoft/BotBuilder/Node/core?master
Run Code Online (Sandbox Code Playgroud)

他们的站点上有一个类似向导的表单,可以帮助构建 URL 以及安装它的命令。


Tom*_*Rup 25

添加到package.json:

...
"scripts": {
  "postinstall": "mkdir BotBuilder; cd BotBuilder; git init; git remote add -f origin https://github.com/Microsoft/BotBuilder.git; git config core.sparseCheckout true; echo \"Node/core\" >> .git/info/sparse-checkout; git pull --depth=1 origin master; cd ..; npm i ./BotBuilder/Node/core/"
  ...
},
...
Run Code Online (Sandbox Code Playgroud)

postinstall 安装包后脚本正在运行.

并一步一步:

  1. 使文件夹克隆回购: mkdir BotBuilder
  2. 进入文件夹: cd BotBuilder
  3. init git repo: git init
  4. 将git origin设置为Microsoft/BotBuilder repo: git remote add -f origin https://github.com/Microsoft/BotBuilder.git
  5. 启用稀疏结账:git config core.sparseCheckout true
  6. 添加Node/core到结帐清单:echo "Node/core" >> .git/info/sparse-checkout
  7. 回购部分: git pull --depth=1 origin master
  8. 进入您的app文件夹: cd ..
  9. 安装BotBuilder: npm i ./BotBuilder/Node/core/


小智 10

将子文件夹的 github 链接粘贴到 gitpkg 中。然后,您可以使用它与 yarn 或 npm 一起从 github 子文件夹安装包。

https://gitpkg.now.sh/

  • 我感兴趣的存储库不断出现 502 错误。例如公共仓库:https://gitpkg.now.sh/vendure-ecommerce/vendure/packages/core?master (3认同)