使用 Npm 从 github 安装特定分支

Install specific branch from github using Npm

我想使用 npm

在我的项目中从 github 安装 bootstrap-loader

目前他们正在维护这个项目的两个版本,它们与 webpack 版本 1 和 2 兼容。

我想安装版本 1。我应该使用什么 npm 命令来安装它?

我尝试使用下面的一种,但它不起作用。

npm install git://github.com/shakacode/bootstrap-loader.git[#v1] --Save 

您尝试的命令中有多余的方括号。

要从 brach-name 分支安装最新版本,您可以使用:

npm install "https://github.com/shakacode/bootstrap-loader.git#branch-name" --save

npm的Doc定义在repo_url之后只能指定tag/version。

这是文档:https://docs.npmjs.com/cli/install

你可以给 git 模式作为版本,yarn 和 npm 足够聪明,可以从 git 仓库中解析。

yarn add any-package@user-name/repo-name#branch-name

或 npm

npm install --save any-package@user-name/repo-name#branch-name

npm: npm install username/repo#branchName --save

纱线: yarn add username/repo#branchName

例如 npm i betimer/rtc-attach#master --save(我的用户名是 betimer)

// this will appear in your package.json:
"rtc-attach": "github:betimer/rtc-attach#master"

有一件事我还想提一下:签入 package.json 以便构建服务器自动拉取更改不是一个好主意。相反,将 npm i(第一个命令)放入构建命令中,让服务器只安装和替换包。

另外注意,如果package.json private 设置为true,有时可能会有影响。

另一种方法是将以下行添加到 package.json 依赖项中:

"package-name": "user/repo#branch"

例如:

"dependencies": {
    ... other dependencies ...

    "react-native": "facebook/react-native#master"
}

然后做npm installyarn install

我正在使用 SSH 验证我的 GitHub 帐户,并在我的项目中安装了一些依赖项,如下所示:

"dependencies": {
  "<dependency name>": "git+ssh://git@github.com/<github username>/<repository name>.git#<release version | branch>"
}

尝试了建议的答案,但只能使用这种前缀方法:

npm i github:user/repo.git#version --save -D

必须将 url 放在引号中才能正常工作

npm install "https://github.com/shakacode/bootstrap-loader.git#v1" --save

唯一适合我的解决方案:

$ npm i https://github.com/{USER}/{REPO}/tarball/{BRANCH} --save

解释为 here