简体   繁体   中英

How can I pass an optional flag to a dependency of my npm package?

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 ... # other deps npm install foo node script_that_uses_foo.js

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": "*" }

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.

Thanks for your help.

I know this is really old, but I believe that in this case, you can

    npm install foo --bar-option=1

npm will pass bar-option through to all dependencies, eg "bar" when installing them.

alternatively, inside of foo's package.json, you could define a preinstall script that does "npm install bar --bar-option=1"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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