使用napi node_使用Napi / node-addon-api和Cmake的独立于Node.js版本的C ++ Native Addon

使用napi node

This is a tutorial for c++ Node-addon-api / Napi addon using cmake.Napi makes it independent of node.js version, means our addon will be compatible with all future version of node.js . Cmake is a cross-platform code compiling tool for c++ code this makes us independent of complex node-gyp process.

这是一个使用cmake的c ++ Node-addon-api / Napi插件教程.Napi使它独立于node.js版本,这意味着我们的插件将与所有以后的node.js版本兼容。 Cmake是用于C ++代码的跨平台代码编译工具,它使我们独立于复杂的node-gyp进程。

要求 :- (Requirements :-)

  1. install Node.js > 10.x

    安装Node.js > 10.x

Note:- Remember to check automatically install the necessary tools.(this will be required to install vs-build tool on windows )

注意:-请记住要检查是否自动安装了必要的工具。(在Windows上安装vs-build工具将需要此工具)

2. install Cmake > 3.15

2. 安装Cmake > 3.15

概述- (Overview -)

  1. Napi addon require four major part

    Napi插件需要四个主要部分
  • package.json file- to handle dependencies, names, version, installation commands etc.

    package.json文件-处理依赖关系,名称,版本,安装命令等。
  • CMakeLists.txt file- commands to needed to compile c++ code.

    CMakeLists.txt文件-编译c ++代码所需的命令。
  • A node script - to use native addon.

    节点脚本-使用本机插件。
  • C++ source files

    C ++源文件

2. Addon will be OS dependent, so if you want to make it cross-platform compatible. Then it will be needed to built(once) on all platforms separately.

2. Addon将取决于操作系统,因此,如果要使其跨平台兼容。 然后,需要分别在所有平台上构建(一次)。

Node.js应用程序(package.json) (Node.js app (package.json))

  1. Make a directory for your project and open terminal/power-shell in it.

    为您的项目创建一个目录,并在其中打开终端/电源外壳。
  2. Since node.js is installed already we will create a project(package.json) using npm.

    由于已经安装了node.js,我们将使用npm创建一个项目(package.json)。
npm init

This will ask you package name, version, description, e

你可能感兴趣的:(vue,ViewUI)