如何在纱线中从github repo安装包

Sil*_*ara 112 node.js yarnpkg

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

我想问一下,该如何做到这一点yarn

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

yarn add fancyapps/fancybox#v2.6.1

Kas*_*eni 166

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.
Run Code Online (Sandbox Code Playgroud)

2.6.1在fancybox git版本中不可用

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]
Run Code Online (Sandbox Code Playgroud)

  • 对于带有私有存储库的 SSH,我发现我们需要添加用户“git”。例如:`yarn add ssh://git@github.com/fancyapps/fancybox#3.0` (6认同)
  • 这在 Yarn 2 中不起作用;您需要在 url 前面添加 `my-package-name@`。请参阅此处:https://github.com/yarnpkg/berry/issues/994#issuecomment-591853492 (3认同)
  • 但不能使用git @ xxx风格 (2认同)
  • 解析模块时可能还需要添加 dist 文件夹。 (2认同)

Ell*_*iot 60

纱线2+

Yarn 2从远程 URL 安装略有变化。具体来说,远程 URL 必须以包名称为前缀。所以对于 github 来说这意味着:

yarn add '<package name>@https://github.com/<github user>/<github repo>'
Run Code Online (Sandbox Code Playgroud)

确保它与存储库文件字段<package name>中的值匹配。"name"package.json

要定位特定分支,请添加head=<branch>commit=<full commit hash>通过 URL 片段:

yarn add '<package name>@https://github.com/<github user>/<github repo>#head=<branch name>'
Run Code Online (Sandbox Code Playgroud)

如果您尝试从 github 上的 Yarn monorepo 安装单个包,您可以添加workspace=<package name>到 URL 片段:

yarn add '<package name>@https://github.com/<github user>/<github repo>#head=<branch name>&workspace=<package name>'
Run Code Online (Sandbox Code Playgroud)


Tyl*_*ler 18

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

yarn add ssh://<whatever>@<xxx>#<branch,tag,commit>
Run Code Online (Sandbox Code Playgroud)

  • 当`yarn`拒绝遵守常见的`git` ssh url语法时,这对我有用:做了以下工作:`yarn add ssh://git@github.com:my-org/my-repo#commit_hash`不起作用: `yarn add git@github.com:my-org/my-repo#commit_hash` (7认同)

lan*_*wen 10

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

例如:

yarn add https://github.com/novnc/noVNC.git#0613d18
Run Code Online (Sandbox Code Playgroud)


bet*_*res 8

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

yarn add github_user/repository_name#commit_hash


Edu*_*omo 6

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

yarn add 'ssh://git@github.com:myproject.git#<branch,tag,commit>'
npm install 'ssh://git@github.com:myproject.git#<branch,tag,commit>'
Run Code Online (Sandbox Code Playgroud)