npm从github repo子文件夹安装软件包 [英] npm install package from github repo subfolder

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

问题描述

是否有可能在子文件夹内安装包时,从github安装npm包?

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



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



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

解决方案添加到 package.json

  ... 
脚本:{
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原点主; cd ..; npm i ./B otBuilder / Node / core /
...
},
...


$

然后循序渐进: postinstall 脚本在安装包后运行。

/ p>


  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. 启用稀疏结帐
  6. a>: git config core.sparseCheckout true
  7. add Node / core 结帐清单: echoNode / core>> .git / info / sparse-checkout

  8. 拉回部分回购: git pull --depth = 1原点大师

  9. 安装BotBuilder:
  10. 安装BotBuilder: npm i ./BotBuilder/Node/core/


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

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

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

So how can I install it with npm?

解决方案

Add to 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 script is running after the package is installed.

And step by step:

  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/

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

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