git - npm 从 github repo 子文件夹安装包

标签 git github npm

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

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

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

那么如何使用 npm 安装它呢?

最佳答案

添加到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/"
  ...
},
...

postinstall 脚本在安装包后运行。

一步一步:

  1. 创建文件夹以克隆 repo:mkdir BotBuilder
  2. 进入文件夹:cd BotBuilder
  3. 初始化 git 仓库:git init
  4. 将 git origin 设置为 Microsoft/BotBuilder 存储库:git remote add -f origin https://github.com/Microsoft/BotBuilder.git
  5. 启用sparse checkout : git config core.sparseCheckout true
  6. Node/core 添加到 checkout 列表:echo "Node/core">> .git/info/sparse-checkout
  7. pull 部分 repo:git pull --depth=1 origin master
  8. 进入你的应用文件夹:cd ..
  9. 安装 BotBuilder:npm i ./BotBuilder/Node/core/

关于git - npm 从 github repo 子文件夹安装包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39194648/

相关文章:

node.js - 将多个变量传递给 package.json 脚本

git - SVN 到 Git 迁移 : Only import certain branches and history

git - 为什么 git 要求输入 key 密码而 ssh 不要求?

git - 我如何知道 git Push 完成了多少百分比?

Github - 在提交消息中创建指向我的 JIRA 问题的链接

javascript - Promise 始终处于待处理状态(语法错误?)

regex - Git 差异 : ignore lines starting with a word

git - 摆脱 temp-xxxx.rdb 文件

ios - 将 Objective-C 框架添加到 Swift XCode 项目

github - Lerna总是在运行Github操作的工作流程时列出所有准备发布的软件包