我正在开发一个大node.js项目还包括几个 native 库。
为了在 JavaScript 中使用这些库,我使用 node-gyp 将它们编译为 Node 插件 (.node
)。 。
我想运行node-gyp一次从根目录递归编译所有可用的 binding.gyp
(在所有子目录中)。
有什么办法可以做到这一点吗?
最佳答案
GYP 允许为目标设置依赖项列表。您可以在顶级 bindings.gyp
中创建一个 type: none
的目标,并列出子目录中的依赖项:
{
'targets': [
{
'target_name': 'build_all',
'type': 'none',
'dependencies': ['subdir1/bindings.gyp:*', 'subdir/subdir2/bindings.gyp:*'],
# or generate dependencies list with a command expansion
'dependencies': ['<!@(find -mindepth 2 -name binding.gyp | sed -e s/$/:*/)'],
}
]
}
这将编译所有依赖项并将它们放入根目录中的 build/
目录中。
要将每个插件放入其相应的目录中,请在插件的 binding.gyp
中添加一个 postbuild
目标:
{
"targets": [
{
"target_name": "my-target",
"sources": [ "example.cpp" ]
},
{
"target_name": "action_after_build",
"type": "none",
"dependencies": [ "my-target" ],
"copies": [
{
"files": [ "<(PRODUCT_DIR)/my-target.node" ],
"destination": "."
}
]
}
]
}
关于node.js - node-gyp:在所有子目录中运行 binding.gyp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38693619/