FakeFullStack / QA

既然我们开源不出轮子,那么就开源坑好了
10 stars 0 forks source link

how to use node-serialport on the electron #5

Open hanfengcan opened 5 years ago

hanfengcan commented 5 years ago

If you want to use node-serialport on your electron app, u need rebuild it on electron. there are two way to rebuild the node-serialport.

make sure you have node-gyp & py2.7.
Visual Studio Build Tools Or VS, if your OS is Windows.

installation via npm

set some env variable, if your system is Linux

export npm_config_target=1.2.3

export npm_config_arch=x64
export npm_config_target_arch=x64

export npm_config_disturl=https://atom.io/download/electron

export npm_config_runtime=electron

export npm_config_build_from_source=true

HOME=~/.electron-gyp npm install

or Windows, use set instead of export

set npm_config_target=1.2.3

set npm_config_arch=x64
set npm_config_target_arch=x64

set npm_config_disturl=https://atom.io/download/electron

set npm_config_runtime=electron

set npm_config_build_from_source=true

you can find version of npm_config_target in here.

Windows

I build the model by Visual Studio Build Tools. try this cmd and npm install node-serialport --save, dont forget to replace the path of VSBT and python

@call "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvars64.bat"

set PYTHON=D:\Python27
set npm_config_target=3.0.2
set npm_config_arch=x64
set npm_config_target_arch=x64
set npm_config_disturl=https://atom.io/download/electron
set npm_config_runtime=electron
set npm_config_build_from_source=true

use electron-rebuild

install electron-rebuild to rebuild

npm install --save-dev electron-rebuild

# linux
./node_modules/.bin/electron-rebuild

windows

set the python path and VSBT in your cmd, then .\node_modules\.bin\electron-rebuild.cmd

the problem when you build

look at the log , mabye:

don't give up and try to fix

hanfengcan commented 5 years ago

If you find the Chinese doc, here