从Git存储库子文件夹安装npm

18
我有一个包含各种组件的存储库,我希望能够将这些组件作为单独的依赖项引入(但我不想为每个组件创建一个存储库)。 有没有一种方法可以在npm中使用github存储库的子文件夹作为依赖项的路径?(而不涉及为每个组件创建单独的分支)
类似于: dropdown: git+https://git@github.com/me/mycomponents.git/components/dropdown

我之前问过一个非常类似的问题(http://stackoverflow.com/q/35416149/5924893),但仍在寻找更好的解决方案。希望你能提供一些有用的建议。 - PostCrafter
@PostCrafter 希望如此 :) - Avraam Mavridis
1个回答

4

你可以使用这种方式。

自从1.7.0版本起,git支持稀疏检出,这正是你所需要的。不幸的是,npm没有任何设置来支持它,因此你必须手动操作。假设你想要从BotBuilder中添加Node/core,请将以下内容添加到你的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/"
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接