来自 github repo 子文件夹的 npm 安装包

编程入门 行业动态 更新时间:2024-10-28 12:19:40
本文介绍了来自 github repo 子文件夹的 npm 安装包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

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

For example, we have Microsoft BotBuilder repository: github/Microsoft/BotBuilder

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

But I need to install package inside subfolder "Node/core/": github/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 github/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.

一步一步:

  • 制作用于克隆 repo 的文件夹:mkdir BotBuilder
  • 进入文件夹:cd BotBuilder
  • init git repo: git init
  • 将 git origin 设置为 Microsoft/BotBuilder 存储库:git remote add -f origin github/Microsoft/BotBuilder.git
  • 启用稀疏结帐:git config core.sparseCheckout true
  • 将 Node/core 添加到结帐列表:echo "Node/core" >>.git/info/sparse-checkout
  • pull 部分仓库:git pull --depth=1 origin master
  • 进入你的应用文件夹:cd ..
  • 安装 BotBuilder:npm i ./BotBuilder/Node/core/
  • Make folder to clone repo: mkdir BotBuilder
  • enter to the folder: cd BotBuilder
  • init git repo: git init
  • set git origin to Microsoft/BotBuilder repo: git remote add -f origin github/Microsoft/BotBuilder.git
  • enable sparse checkout: git config core.sparseCheckout true
  • add Node/core to checkout list: echo "Node/core" >> .git/info/sparse-checkout
  • pull part of repo: git pull --depth=1 origin master
  • enter to Your app folder: cd ..
  • install BotBuilder: npm i ./BotBuilder/Node/core/
  • 更多推荐

    来自 github repo 子文件夹的 npm 安装包

    本文发布于:2023-07-04 17:27:58,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1027085.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:文件夹   安装包   github   repo   npm

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!