看起来 yarn
不像 npm
那样将 node-gyp 标志传递给 native 包。
例如,当尝试安装 sqlite3@3.1.6 时:
npm install sqlite3@3.1.6 \
--build-from-source \
--sqlite_libname=sqlcipher \
--sqlite=`brew --prefix` \
--verbose
我们成功安装了带有 sqlcipher 扩展的 sqlite3,因为传递了 --sqlite_libname
和 --sqlite
,它们是 specified在 sqlite3 的 binding.gyp
中。
但是,当尝试使用 yarn
并运行我认为等效的命令时,看起来标志不被尊重:
yarn add sqlite3@3.1.6 \
--force \
--build-from-source \
--sqlite_libname=sqlcipher \
--sqlite=`brew --prefix` \
--verbose
使用 npm
无法识别的命令行参数被转换为 gyp 标志。
使用 yarn
似乎不起作用。
有没有办法通过 yarn
获得这个功能?
最佳答案
目前可以通过使用 npm_config_{snake_case_param}=true/false 格式的环境变量
例如,npm install --build-from-source=true
变为:
npm_config_build_from_source=true yarn install
这里记录了 https://yarnpkg.com/lang/en/docs/envvars/#toc-npm-config
关于node.js - 将 node-gyp 标志传递给包时, yarn add package --build-from-source 的行为是否类似于 npm install package --build-from-source?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45758461/