问题描述
我正在开发一个 npm 包,我们称之为 foo
,它有一些外部依赖项.其中一个依赖项 bar
需要一个构建标志才能使用我的项目.如果我要手动安装依赖项,我会说:
I'm working on an npm package, let's call it foo
, that has a few external dependencies. One such dependency, bar
requires a build flag in order to work with my project. If I were to manually install the dependencies I would say:
npm install bar --bar-option=1... # 其他 depsnpm 安装 foo节点 script_that_uses_foo.js
我希望使用 npm install foo
自动安装 foo
的依赖项.所以我的 package.json
文件中有一个部分如下所示:依赖关系":{"bar": "文件:../../bar-0.1.0.tgz","baz": "*"}
I would like the dependencies of foo
to be installed automatically with npm install foo
. So I have a section in my package.json
file that looks like this: "dependencies" : { "bar": "file:../../bar-0.1.0.tgz", "baz": "*" }
这很好用,除了 bar
安装时没有 --bar-option=1
.如何告诉 npm
将此参数传递给 bar
的安装脚本?我浏览了 npm 文档 并没有找到我要找的东西.
This works fine, except that bar
is installed without --bar-option=1
. How can I tell npm
to pass this argument to the install script of bar
? I've looked through the npm documentation and haven't found what I'm looking for.
感谢您的帮助.
推荐答案
我知道这真的很旧,但我相信在这种情况下,你可以
I know this is really old, but I believe that in this case, you can
npm install foo --bar-option=1
npm 会将 bar-option 传递给所有依赖项,例如安装它们时bar".
npm will pass bar-option through to all dependencies, e.g. "bar" when installing them.
或者,在 foo 的 package.json 中,您可以定义一个执行npm install bar --bar-option=1"的预安装脚本
alternatively, inside of foo's package.json, you could define a preinstall script that does "npm install bar --bar-option=1"
这篇关于如何将可选标志传递给我的 npm 包的依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!