问题
My node.js project has a dependency on node-sqlite, but unfortunately the default libsqlite binary embedded there was not built with options I need.
Now I can invoke npm install on that package alone to get it to build correctly:
CFLAGS=-DSQLITE_ENABLE_STAT4 npm install sqlite3 --build-from-source
Essentially, this sets the environment variable and passes an option to the tool.
However, npm install by itself should just install all the project dependencies, including sqlite. How do I encode package.json or elsewhere so that npm install will install the sqlite dependency with the above command line?
回答1:
You could use a preinstall or a postinstall script to do this.
#!/bin/bash
CFLAGS=-DSQLITE_ENABLE_STAT4 npm install sqlite3 --build-from-source;
Put this in scripts/install_sqlite3_from_source.sh, and set scripts.preinstall or scripts.postinstall in your package.json to it.
来源:https://stackoverflow.com/questions/34822510/how-to-pass-options-to-dependent-package-installs-for-npm