[英]npm install from github repository not installing devDependencies
我正在尝试直接从 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 存储库链接执行相同的安装?
这是因为当您使用npm install web3
,npm 将安装web3作为您应用程序的包依赖项。
您在 node_module 文件夹中看到的 5 个依赖项是web3.js需要运行的依赖项。
不确定使用 npm 是否有内置选项,但是您可以使用以下命令安装此软件包的开发版本:
$ 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
花了一个小时的时间来解决这个问题,直到我终于在npm-install文档的npm install <git remote url>
部分下偶然发现了这句话:
如果正在安装的包包含准备脚本,则在打包和安装包之前,将安装其依赖项和 devDependencies,并运行准备脚本。
这非常适合我的用例,因为我想安装我自己的私有仓库,然后构建它以便dist
文件夹可用。 我可以将此脚本添加到该私有仓库的package.json
:
"scripts": {
"prepare": "npm run build"
}
现在所有依赖项都可用于构建步骤,该步骤将在npm install
上自动npm install
。 准备脚本还与其他一些事件一起运行,例如打包和发布,因此请确保该包的其余构建步骤反映了这一点。
许多公共包已经有了这个脚本,所以npm install
可以直接在他们的 git repos 上npm install
,但是如果包没有(看起来web3.js仍然没有),你可能需要 fork 并插入你自己的脚本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.