Windows環(huán)境
工具包:
npm install --vs2015 -g windows-build-tools
首先安裝
1.npm install sqlite3 --save or yarn add sqlite3
2.npm install node-gyp -g
sqlite3 在打包安裝的時候需要生成二進制文件包所以需要node-gyp編一個版本這里有個坑:
node-gyp rebuild --target=5.0.2 --arch=ia32 --target_platform=win32 --dist-url=https://atom.io/download/electron/ --module_name=node_sqlite3 --module_path=../lib/binding/electron-v5.0-win32-ia32
node-gyp rebuild --target=4.0.0 --arch=x64 --target_platform=darwin --dist-url=https://atom.io/download/electron/ --module_name=node_sqlite3 --module_path=../lib/binding/node-v64-darwin-x64
// target : 必須與electron的版本號相同
// target_platform : 這里是需要打包的平臺ia32/x64
// dist-url : 這個是需要下載相關(guān)內(nèi)容的地址
// module_name : 需要打包的模塊名稱
// module_path : 打包輸出的地方
報錯1.:gyp: binding.gyp not found (cwd: /Users/xx/xx) while trying to load binding.gyp
解決:需要在 packag.json 同級目錄下創(chuàng)建一個 binding.gyp文件
內(nèi)容為:
{
"targets": [
{
"target_name": "binding",
"sources": [ "src/binding.cc" ]
}
]
}
其實這些https://github.com/nodejs/node-gyp 這里都有當時沒注意
報錯2:
make: *** No rule to make target Release/obj.target/binding/src/binding.o needed by Release/binding.node'. Stop.
解決:src/binding.cc查看這個目錄文件有沒有.沒有需要創(chuàng)建就解決了
報錯 3:Cannot find module /xxnode_modules/sqlite3/lib/binding/electron-v5.0-darwin-x64/node_sqlite3.node
解決方法:
首先:
在 packag.json 添加
"scripts": {
"postinstall": "install-app-deps"
...
}
npm install --save-dev electron-builder
npm install --save sqlite3
npm run postinstall
后面我邊開發(fā)遇到問題在繼續(xù)寫