来自 github repo 子文件夹的 npm 安装包 [英] npm install package from github repo subfolder

查看:33
本文介绍了来自 github repo 子文件夹的 npm 安装包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is it possible to install npm package from github when the package located inside subfolder?

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

For example, we have Microsoft BotBuilder repository: https://github.com/Microsoft/BotBuilder

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

But I need to install package inside subfolder "Node/core/": https://github.com/Microsoft/BotBuilder/tree/master/Node/core/

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

So how can I install it with 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 脚本在安装包后运行.

postinstall script is running after the package is installed.

一步一步:

  1. 制作用于克隆 repo 的文件夹:mkdir BotBuilder
  2. 进入文件夹:cd BotBuilder
  3. init git repo: git init
  4. 将 git origin 设置为 Microsoft/BotBuilder 存储库: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. pull 部分仓库:git pull --depth=1 origin master
  8. 进入你的应用文件夹:cd ..
  9. 安装 BotBuilder:npm i ./BotBuilder/Node/core/
  1. Make folder to clone repo: mkdir BotBuilder
  2. enter to the folder: cd BotBuilder
  3. init git repo: git init
  4. set git origin to Microsoft/BotBuilder repo: git remote add -f origin https://github.com/Microsoft/BotBuilder.git
  5. enable sparse checkout: git config core.sparseCheckout true
  6. add Node/core to checkout list: echo "Node/core" >> .git/info/sparse-checkout
  7. pull part of repo: git pull --depth=1 origin master
  8. enter to Your app folder: cd ..
  9. install BotBuilder: npm i ./BotBuilder/Node/core/

这篇关于来自 github repo 子文件夹的 npm 安装包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆