node-gyp 是用于原生 Node.js 插件的标准构建工具,并且被 npm 生态系统中的绝大多数包使用。它由 Node.js 团队积极维护。本网站上的大多数示例使用 node-gyp 来构建二进制文件。
node-gyp 基于谷歌的 GYP 构建工具。GYP 为 C/C++ 构建提供了单一的跨平台配置格式。尽管谷歌已将上游 GYP 仓库归档,node-gyp 仍通过 gyp-next 接收积极的开发和维护。
🌐 node-gyp is based on Google's GYP build tool. GYP provides a single cross-platform configuration format for C/C++ builds. Although Google archived the upstream GYP repository, node-gyp continues to receive active development and maintenance through gyp-next.
node-gyp 需要 Python 3.6 或更高版本。不支持 Python 2。每个平台的完整要求列表可以在 node-gyp 安装文档 中找到。
node-gyp 已包含在 npm 中;当 npm 在 package.json 中看到 "gypfile": true 时,会在 npm install 期间自动调用 node-gyp。你也可以直接安装并使用它:
🌐 node-gyp is included with npm; when npm sees "gypfile": true in package.json, it invokes node-gyp automatically during npm install. You can also install and use it directly:
npm install -g node-gyp对于觉得 node-gyp 太受限制的开发者,CMake.js 是一个不错的替代选择。
🌐 For developers who find node-gyp too constraining, CMake.js is a good alternative.
🌐 Pros
- 包含在 npm 中 - 消费者无需单独全局安装。
- 几乎在 Node.js 生态系统中被普遍使用,拥有广泛的文档和社区知识。
- 支持从单一的
binding.gyp配置文件运行 Windows、macOS 和 Linux。
🌐 Cons
- Google 不再积极开发底层的 GYP 格式。
- 一些开发者发现 GYP 的配置语法冗长或难以调试。