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