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

JSm*_*oth 4 git github node.js npm

我尝试直接从 GitHub ( https://github.com/ethereum/web3.js ) 安装 ethereum/web3.js 存储库,但未安装 devDependency(仅安装依赖项)。我已经尝试过以下方法:

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
Run Code Online (Sandbox Code Playgroud)

上面的前 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": "*"
},
Run Code Online (Sandbox Code Playgroud)

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

npm install web3 
Run Code Online (Sandbox Code Playgroud)

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

law*_*itt 5

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

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

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

"scripts": {
  "prepare": "npm run build"
}
Run Code Online (Sandbox Code Playgroud)

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

许多公共软件包已经有了这个脚本,因此npm install可以直接在他们的 git 存储库上工作,但是如果该软件包没有(看起来web3.js仍然没有),您可能必须分叉它并插入您自己的脚本脚本。