可以将选项添加到 npm package.json 依赖项中吗? [英] can options be added to npm package.json dependencies?

查看:100
本文介绍了可以将选项添加到 npm package.json 依赖项中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我依赖于 sqlite3 包.

I have a dependency with the sqlite3 package.

默认情况下,在安装时,sqlite3 包会下载并使用 sqlite3 引擎的预打包版本.这在使用 sqlite3 扩展时有时会出现问题,因此可以选择安装它:

By default, upon install, the sqlite3 package downloads and uses a pre-packaged version of the sqlite3 engine. This can sometimes be a problem when using sqlite3 extensions so there is an option to install it with :

npm install --build-from-source --sqlite=/path/to/sqlite sqlite3

--build-from-source"和--sqlite"都是由 sqlite3 包处理的选项.

both "--build-from-source" and "--sqlite" are options that are handled by the sqlite3 package.

现在如何告诉 package.json 使用这些选项安装我的依赖项?

Now how can I tell package.json to install my dependency with those options ?

"dependencies": {
    "sqlite3": "*"
 }

显然我得到了等价于

npm install sqlite3

但我找不到强制 sqlite3 包的 --build-from-source 和 --sqlite 选项的方法

but I cannot find a way to force the --build-from-source and --sqlite options for the sqlite3 package

推荐答案

另一种方法是使用 scripts 成员并在 preinstall 或 postinstall 挂钩下设置安装脚本:

An alternative is to use the scripts member and setup the install script under the preinstall or postinstall hook:

"scripts": {
  "preinstall": "npm install --build-from-source --sqlite=/path/to/sqlite sqlite3"
},

这篇关于可以将选项添加到 npm package.json 依赖项中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆