How to pass options to dependent package installs for npm?

末鹿安然 提交于 2020-01-04 08:04:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!