当包位于子文件夹中时,是否可以从github安装npm包?
例如,我们有Microsoft BotBuilder存储库:https: //github.com/Microsoft/BotBuilder
但我需要在子文件夹"Node/core /"中安装软件包:https: //github.com/Microsoft/BotBuilder/tree/master/Node/core/
那么如何用npm安装呢?
Sha*_*aee 31
如果包源托管在 GitHub 上,您可以像这样使用GitPkg :
# using npm:
npm install https://gitpkg.now.sh/<user>/<project>/<subdir>?<commit-ish>
# using yarn:
yarn add https://gitpkg.now.sh/<user>/<project>/<subdir>?<commit-ish>
Run Code Online (Sandbox Code Playgroud)
对于您的特定情况,URL 将是这样的:
https://gitpkg.now.sh/Microsoft/BotBuilder/Node/core?master
Run Code Online (Sandbox Code Playgroud)
他们的站点上有一个类似向导的表单,可以帮助构建 URL 以及安装它的命令。
Tom*_*Rup 25
添加到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/"
...
},
...
Run Code Online (Sandbox Code Playgroud)
postinstall 安装包后脚本正在运行.
并一步一步:
mkdir BotBuildercd BotBuildergit initgit remote add -f origin https://github.com/Microsoft/BotBuilder.gitgit config core.sparseCheckout trueNode/core到结帐清单:echo "Node/core" >> .git/info/sparse-checkoutgit pull --depth=1 origin mastercd ..npm i ./BotBuilder/Node/core/小智 10
将子文件夹的 github 链接粘贴到 gitpkg 中。然后,您可以使用它与 yarn 或 npm 一起从 github 子文件夹安装包。