electron安裝sqlite3


By far the easiest way to use SQLite with electron is with electron-builder.

First, add a postinstall step in your package.json:

"scripts": { "postinstall": "install-app-deps" ... } 

and then install the necessary dependencies and build:

npm install --save-dev electron-builder npm install --save sqlite3 npm run postinstall 

electron-builder will build the native module for your platform, with the correct name for the Electron binding; and you can then require it in code as normal.

前面已經描述的很好,這么干的原因是,你通過npm install sqlite3安裝的sqlite3是node的支持,不支持electron,要重新編譯一個electron的版本。
在做這個之前,要把window平台的編譯支持安裝上。

下面是通用做法

1.安裝window下的c++編譯支持
2.安裝electron-builder,
3.安裝sqlite3.
4重新編譯electron支持的sqlite3

第4步可以使用npm install安裝所有依賴時觸發postinstall鈎子,也可以直接npm run postinstall

有一個我沒有執行成功的做法
 1.安裝electron-rebuild.
 2.配置scripts腳本
   "rebuild": "electron-rebuild -f -w sqlite3" 

手動執行沒有成功,不過我根據報錯,分析出下載地址,自己把文件下載下來,放在sqlite3模塊binding文件夾相應的平台文件夾里,可以用的。
https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v4.1.0/electron-v6.0-win32-x64.tar.gz
   electron-builder install-app-deps 我手動執行這個,成功了,就編譯出來了。
還有直接編譯法
   npm install sqlite3 --build-from-source --runtime=electron --target=2.0.7 --dist-url=https://atom.io/download/electron
 --target 參數的值是你安裝的 electron 的版本
  這個方案我沒有執行成功,編譯報錯。
最簡單方案


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM