npm从github存储库安装而不是安装devDependencies

时间:2017-11-17 20:43:32

标签: node.js git github npm

我正在尝试直接从GitHub(https://github.com/ethereum/web3.js)安装ethereum / web3.js存储库,但是没有安装devDependencies(只有依赖项)。我尝试过以下方法:

npm install https://github.com/ethereum/web3.js.git
npm install git+https://github.com/ethereum/web3.js.git
npm install ethereum/web3.js
npm install https://github.com/ethereum/web3.js.git --only=dev
npm install git+https://github.com/ethereum/web3.js.git --only=dev
npm install ethereum/web3.js --only=dev

上面的前3个命令只会在web3.js的package.json文件的依赖项部分安装5个依赖项,而3" - only = dev"命令不会安装任何东西。

"dependencies": {
    "bignumber.js": "git+https://github.com/frozeman/bignumber.js-
nolookahead.git",
    "crypto-js": "^3.1.4",
    "utf8": "^2.1.1",
    "xhr2": "*",
    "xmlhttprequest": "*"
},

当我使用以下命令时,安装了288个软件包:

npm install web3 

如何使用GitHub存储库链接执行相同的安装?

2 个答案:

答案 0 :(得分:0)

这是因为当您使用npm install web3时,npm会将 web3 安装为您的应用程序的软件包依赖项。
您在node_module文件夹中看到的5个依赖项是 web3.js 需要运行的依赖项。

不确定npm是否有内置选项,但您可以使用以下命令安装此软件包的developpement版本:

$ npm install --save https://github.com/ethereum/web3.js.git \
  && cd node_modules/web3/ \
  && npm install --only=dev

或者更传统的东西:

$ git clone https://github.com/ethereum/web3.js.git \
  && cd web3.js \
  && npm install --only=dev

答案 1 :(得分:0)

花了一个小时的时间来解决这个问题,直到我终于在 npm-install 文档的 npm install <git remote url> 部分下偶然发现了这句话:

<块引用>

如果正在安装的包包含准备脚本,则在打包和安装包之前,将安装其依赖项和 devDependencies,并运行准备脚本。

这非常适合我的用例,因为我想安装自己的私有存储库,然后构建它以便 dist 文件夹可用。我可以将此脚本添加到该私有存储库的 package.json:

"scripts": {
  "prepare": "npm run build"
}

现在所有依赖项都可用于构建步骤,该步骤将在 npm install 上自动运行。 prepare script 还与其他一些事件一起运行,例如打包和发布,因此请确保该包的其余构建步骤反映了这一点。

许多公共包已经有了这个脚本,所以 npm install 将直接在他们的 git repos 上工作,但如果包没有(看起来 web3.js 仍然没有)您可能需要 fork 并插入您自己的脚本。

相关问题