第一步:electron-vue环境的搭建、项目的创建
npminstall -g vue-clivueinit simulatedgreg/electron-vue my-project(这个是项目名称,根据实际需要修改)cdmy-projectnpminstall(查看项目是否运行成功)npmrun dev
第二步:安装node-gyp(需要注意node如果为64位,可能需要转为32位,64位可能导致后面编译失败)
需要安装VS2017和python
npm install -g node-gyp
npm install --global --production windows-build-tools
(直接安装这两个工具)
npm config set python python2.7
npm config set msvs_version 2019
npm config set python C:\Python27(指定python2的路径)
测试是否安装完成:
node-gyp
成功显示:
Usage:node-gyp [options] where is one of: -build - Invokes `msbuild`and builds the module - clean - Removes any generatedbuild filesand the"out"dir- configure - Generates MSVC project files for the current module - rebuild - Runs"clean","configure"and "build"allatonce -install -Install node development files for the specified node version. - list - Prints a listing of the currentlyinstalled node development files - remove - Removes the node development files for the specified versionnode-gyp@6.1.0H:\npm\node_global\node_modules\node-gypnode@8.16.2
第三步: 安装serialport,通过 electron-rebuild 包重新编译原生模块
npm install serialport
npm install --save-dev electron-rebuild
重新编译
.\node_modules\.bin\electron-rebuild.cmd重新编译完成之后, 如果运行npmrundev就会报错,说明编译失败了,需要进行手动编译
防止出现gyp: binding.gyp not found的错误,我使用手动编译,步骤如下:
cd ./node_modules/@serialport/bindings(项目路径不能有中文,否则编译识别)
(npm是64位的)node-gyp rebuild --target=2.0.4 --arch=x64 --dist-url=https://npm.taobao.org/mirrors/atom-shell
(npm是32位的)node-gyp rebuild --target=2.0.4 --arch=ia32 --dist-url=https://npm.taobao.org/mirrors/atom-shell