使用非模块的 npm 安装库

Installing a library with npm that is not a module

我正在从事一个需要 WebGazer.js (https://webgazer.cs.brown.edu/) 的项目。我很想以某种方式将这个库添加到 package.json 以便我的所有库都使用 'npm install' 安装,而不必调用 'npm install' 然后单独下载 webgazer。

有没有办法通过包含 link 或类似的东西来做到这一点?我是 npm 的新手,所以我不知道从哪里开始,或者这是否可能。

npm install 仅适用于模块。但是,WebGazer 有一个 package.json 的 NPM,这就是你所需要的。 (该模块不需要在 NPM 存储库中列出。)

尝试这样的事情:

npm install --save git+https://git@github.com/brownhci/WebGazer.git

如果您确实遇到了您描述的问题,您可以设置一个 postinstall 脚本来安装您需要的任何其他东西,但是您需要它。 https://docs.npmjs.com/misc/scripts

对于那些想知道如何安装您自己创建的非 node_module 依赖项且位于 git 上的人:

只需将 package.json 文件添加到您的(非 node_module)依赖项中,至少看起来像这样:

{
  "name": "your-dependency-name",
  "version": "1.0.0",
  "repository": {
    "type": "git",
    "url": "https://github.com/<user>/<repo>.git"
  }
}

然后在您的 'mother' 项目中关注 ryanve's answer

It can be done via ssh or via https and oauth.

https and oauth: create an access token that has "repo" scope and then use this syntax:

"package-name": "git+https://:x-oauth-basic@github.com//.git" ssh: setup ssh and then use this syntax:

"package-name": "git+ssh://git@github.com//.git"

(感谢Brad之前说的)