当包位于子文件夹中时,是否可以从 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
脚本在安装包后运行。
一步一步:
- 创建文件夹以克隆 repo:
mkdir BotBuilder
- 进入文件夹:
cd BotBuilder
- 初始化 git 仓库:
git init
- 将 git origin 设置为 Microsoft/BotBuilder 存储库:
git remote add -f origin https://github.com/Microsoft/BotBuilder.git
- 启用sparse checkout :
git config core.sparseCheckout true
- 将
Node/core
添加到 checkout 列表:echo "Node/core">> .git/info/sparse-checkout
- pull 部分 repo:
git pull --depth=1 origin master
- 进入你的应用文件夹:
cd ..
- 安装 BotBuilder:
npm i ./BotBuilder/Node/core/
关于git - npm 从 github repo 子文件夹安装包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39194648/