How to pass options to dependent package installs

2019-07-09 07:29发布

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条回答
别忘想泡老子
2楼-- · 2019-07-09 07:47

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.

查看更多
登录 后发表回答