简体   繁体   English

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

[英]npm install from github repository not installing devDependencies

I am trying to install the ethereum/web3.js repository directly from GitHub ( https://github.com/ethereum/web3.js ), but the devDependencies are not being installed (only the dependencies).我正在尝试直接从 GitHub ( https://github.com/ethereum/web3.js ) 安装 ethereum/web3.js 存储库,但未安装 devDependencies(仅安装依赖项)。 I have tried the following:我尝试了以下方法:

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

The first 3 commands above will only install the 5 dependencies in the dependencies section of web3.js's package.json file, and the 3 "--only=dev" commands won't install anything.上面的前 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": "*"
},

When I use the following command, 288 packages are installed:当我使用以下命令时,安装了 288 个软件包:

npm install web3 

How do I perform the same installation using the GitHub repository link?如何使用 GitHub 存储库链接执行相同的安装?

This is because when you use npm install web3 , npm will install web3 as a package dependency of your application.这是因为当您使用npm install web3 ,npm 将安装web3作为应用程序的包依赖项。
The 5 dependencies you see in your node_module folder are the dependencies web3.js needs to run.您在 node_module 文件夹中看到的 5 个依赖项是web3.js需要运行的依赖

Not sure there is a builtin option do to it with npm, but you can install developpement version of this package with:不确定使用 npm 是否有内置选项,但是您可以使用以下命令安装此软件包的开发版本:

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

Or with something more traditional:或者更传统的东西:

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

Spent a good hour fighting with this until I finally stumbled over this sentence on the npm-install documentation, under the section npm install <git remote url> :花了一个小时的时间来解决这个问题,直到我终于在npm-install文档的npm install <git remote url>部分下偶然发现了这句话:

If the package being installed contains a prepare script, its dependencies and devDependencies will be installed, and the prepare script will be run, before the package is packaged and installed.如果正在安装的包包含准备脚本,则在打包和安装包之前,将安装其依赖项和 devDependencies,并运行准备脚本。

This was perfect for my use case because I wanted to install my own private repo, then build it so the dist folder was available.这非常适合我的用例,因为我想安装我自己的私有仓库,然后构建它以便dist文件夹可用。 I could just add this script to that private repo's package.json :我可以将此脚本添加到该私有仓库的package.json

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

Now all the dependencies are available for the build step which will be run automatically on npm install .现在所有依赖项都可用于构建步骤,该步骤将在npm install上自动npm install The prepare script is also run alongside a few other events, like packing and publishing, so make sure the rest of your build steps for that package reflect that. 准备脚本还与其他一些事件一起运行,例如打包和发布,因此请确保该包的其余构建步骤反映了这一点。

Many public packages have this script already in place, so npm install will work on their git repos straight of out the box, but if the package does not (as it appears web3.js still does not) you may have to fork it and insert your own script.许多公共包已经有了这个脚本,所以npm install可以直接在他们的 git repos 上npm install ,但是如果包没有(看起来web3.js仍然没有),你可能需要 fork 并插入你自己的脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM