问题描述
我的 node.js
工程对 node-sqlite
有一个依赖,但不幸的是默认 libsqlite
二进制嵌入没有用我需要的选项构建。
现在我可以调用
npm install 单独的程序包以使其正确建立: CFLAGS = -DSQLITE_ENABLE_STAT4 npm install sqlite3 --build -from-source
基本上,这会设置环境变量并将一个选项传递给工具。但是, npm install
本身应该只是安装所有项目依赖项,包括sqlite。我如何编码 package.json
或其他地方,使 npm install
将安装sqlite依赖与上述命令行?
解决方案您可以使用脚本。
#!/ bin / bash
CFLAGS = -DSQLITE_ENABLE_STAT4 npm install sqlite3 --build-from-source;
将此文件放在 scripts / install_sqlite3_from_source.sh
,并在 package.json $中设置 scripts.preinstall
或 scripts.postinstall
c $ c>到它。
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?
解决方案 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.
这篇关于如何将选项传递到npm的依赖包安装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!