electron 安装sqlite3 教程

折腾了一天终于解决了,看了很多其他博客,都是比较片面,最终出现各种问题.现自己整理一篇完整版.

方案一: (自定义编译sqlite)

环境:vs2015 ,先安装vs2015 

下载地址:https://my.visualstudio.com/Downloads?q=visual%20studio%202015&wt.mc_id=o~msft~vscom~older-downloads

1: npm install --vs2015 windows-build-tools -g  (这个用 vs2019会卡住,下载很慢)

2: npm install node-gyp -g 

3: npm config set msvs_version 2015 --global  

4: npm config set python C:\Python27\python.exe //无需配置 (第一步会自动安装python2.7,这个版本会提示太低,自己到官网下载 3.6以上版本,并配置全局变量即可)

5: node-gyp configure --module_name=node_sqlite3 --module_path=../lib/binding/electron-v14.0.0-win32-x64

6: node-gyp rebuild --target=14.0.0 --arch=x64 --target_platform=win32 --dist-url=https://atom.io/download/electron/ --module_name=node_sqlite3 --module_path=../lib/binding/electron-v14.0.0-win32-x64

(14.0.0 electron版本号, sqlite默认安装的是适合node原生环境,在electron中必须进行二次编译才能用)

在上面执行过程中也可能出现各种错误,不要慌:

q1----如果出现 缺少windows SDK8.1问题, 在控制面板找到安装的vs2015->点击修改,选择sdk安装即可.

q2---如果出现​​​​​​问题安装 sqlite3 (..\src\database.cc(35): error C2248: 'Napi::Env::DefaultFini': 无法访问类 'Napi::Env' 中声明的私有成员

则可能是因为sqlite安装的版本太高, 还没正式发布,可删了重装

npm install sqlite3@5.0.0   再进行编译即可.

q3----如果出现 找不到python问题, 就自己下载安装 并配置全局变量

方案二:

基于 electron-builder  (推荐,脚手架会出现一些解决不了坑), 会自动编译,不需要自定义配置编译sqlite3这中node 原生模块,

环境: 先安装vs2015 + python3.6+  

环境没问题的情况下:

npm install sqlite3 --save
npm install electron-rebuild --save
.\node_modules\.bin\electron-rebuild.cmd

即便一步步来,也有可能出错,根据log自行 搜索吧

{
  "name": "CTYTHApp",
  "author": "j8",
  "version": "2.0.4",
  "main": "main.js",
  "scripts": {
    "rebuild": "electron-rebuild -f -w sqlite3",
    "electron": "electron . --inspect",
    "build": "electron-builder --win --x64",
    "uos": "electron-builder build --arm64",
    "build:l": "electron-builder --linux --arm64",
    "postinstall": "install-app-deps"
  },
  "build": {
    "productName": "CTYTHApp",
    "appId": "com.htsz.ctyth",
    "electronVersion": "4.1.4",
    "copyright": "j8",
    "asar": false,
    "directories": {
      "output": "dist"
    },
    "publish": [
      {
        "provider": "generic",
        "url": "http://192.168.0.242/download/upgrade/ctyth"
      }
    ],
    "win": {
      "icon": "../src/assets/app/desktop.ico",
      "requestedExecutionLevel": "highestAvailable",
      "target": [
        {
          "target": "nsis",
          "arch": [
            "x64"
          ]
        }
      ]
    },
    "linux": {
      "target":  { "target": "dir", "arch": "arm64" },
      "icon": "../src/assets/app/desktop.png"
    },
    "afterPack": "AfterPackHook.js",
    "nsis": {
      "oneClick": false,
      "allowElevation": true,
      "allowToChangeInstallationDirectory": true,
      "installerIcon": "../src/assets/app/logo.ico",
      "uninstallerIcon": "../src/assets/app/uninstall.ico",
      "installerHeaderIcon": "../src/assets/app/logo.ico",
      "createDesktopShortcut": true,
      "createStartMenuShortcut": true,
      "shortcutName": "j8",
      "include": "../build/znfz.nsi"
    }
  },
  "dependencies": {
    "archiver": "^3.0.0",
    "bluebird": "^3.5.2",
    "cmd": "^0.1.0",
    "compressing": "^1.5.1",
    "electron-updater": "4.0.6",
    "image-base64": "^1.0.2",
    "lodash": "^4.17.11",
    "mkdirp": "^0.5.1",
    "qs": "^6.5.2",
    "request": "^2.88.0",
    "split.js": "^1.6.2",
    "sqlite3": "^5.0.0",
    "stream-to-blob": "^1.0.1",
    "xml2js": "^0.4.19"
  },
  "devDependencies": {
    "child_process": "^1.0.2",
    "electron": "^4.1.4",
    "electron-builder": "^20.39.0",
    "electron-rebuild": "^1.11.0"
  }
}

electron-rebuild  参数:

  1. Options:

  2. -h, --help Show help [boolean]

  3. -v, --version The version of Electron to build against

  4. -f, --force Force rebuilding modules, even if we would skip

  5. it otherwise

  6. -a, --arch Override the target architecture to something

  7. other than your system's

  8. -m, --module-dir The path to the app directory to rebuild

  9. -w, --which-module A specific module to build, or comma separated

  10. list of modules. Modules will only be rebuilt if they

  11. also match the types of dependencies being rebuilt

  12. (see --types).

  13. -e, --electron-prebuilt-dir The path to electron-prebuilt

  14. -d, --dist-url Custom header tarball URL

  15. -t, --types The types of dependencies to rebuild. Comma

  16. separated list of "prod", "dev" and "optional".

  17. Default is "prod,optional"

  18. -p, --parallel Rebuild in parallel, this is enabled by default

  19. on macOS and Linux

  20. -s, --sequential Rebuild modules sequentially, this is enabled by

  21. default on Windows

  22. -o, --only Only build specified module, or comma separated

  23. list of modules. All others are ignored.

  24. -b, --debug Build debug version of modules

  25. --prebuild-tag-prefix GitHub tag prefix passed to prebuild-install.

  26. Default is "v"

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值