node.js 如何从 Yarn 中的 github repo 安装包

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43411864/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 18:09:47  来源:igfitidea点击:

How to install package from github repo in Yarn

node.jsyarnpkg

提问by Silver Zachara

When I use npm install fancyapps/fancybox#v2.6.1 --save, so fancybox package at v2.6.1 tag will be installed. This behavior is described in docs

当我使用 时npm install fancyapps/fancybox#v2.6.1 --save,将安装 v2.6.1 标记的fancybox 包。文档中描述了此行为

I want to ask, how to do this with yarn?

我想问一下,这个怎么办yarn

Is this command the right alternative? In yarn docsisn't anything about this format.

这个命令是正确的选择吗?在纱线文档中与此格式无关。

yarn add fancyapps/fancybox#v2.6.1

yarn add fancyapps/fancybox#v2.6.1

回答by Kasiriveni

You can add any Git repository (or tarball) as a dependency to yarnby specifying the remote URL (either HTTPS or SSH):

您可以yarn通过指定远程 URL(HTTPS 或 SSH)将任何 Git 存储库(或 tarball)添加为依赖项:

yarn add <git remote url> installs a package from a remote git repository.
yarn add <git remote url>#<branch/commit/tag> installs a package from a remote git repository at specific git branch, git commit or git tag.
yarn add https://my-project.org/package.tgz installs a package from a remote gzipped tarball.

Here are some examples:

这里有些例子:

yarn add https://github.com/fancyapps/fancybox [remote url]
yarn add ssh://github.com/fancyapps/fancybox#3.0  [branch]
yarn add https://github.com/fancyapps/fancybox#5cda5b529ce3fb6c167a55d42ee5a316e921d95f [commit]

(Note: Fancybox v2.6.1 isn't available in the Git version.)

(注意:Fancybox v2.6.1 在 Git 版本中不可用。)

回答by Tyler

For ssh style urls just add ssh before the url:

对于 ssh 样式的 url,只需在 url 前添加 ssh:

yarn add ssh://<whatever>@<xxx>#<branch,tag,commit>

回答by lanwen

This is described here: https://yarnpkg.com/en/docs/cli/add#toc-adding-dependencies

这在这里描述:https: //yarnpkg.com/en/docs/cli/add#toc-adding-dependencies

For example:

例如:

yarn add https://github.com/novnc/noVNC.git#0613d18

回答by Eduardo Cuomo

For GitHub(or similar) private repository:

对于GitHub(或类似)私有存储库:

yarn add 'ssh://[email protected]:myproject.git#<branch,tag,commit>'
npm install 'ssh://[email protected]:myproject.git#<branch,tag,commit>'

回答by betoharres

I use this short format for github repositories:

我对 github 存储库使用这种短格式:

yarn add github_user/repository_name#commit_hash

yarn add github_user/repository_name#commit_hash