内容简介:会将程序退出时,需要终止子进程
1、配置 Server
打包位置
// vue.config.js pluginOptions: { electronBuilder: { builderOptions: { //... // 匹配server中的所有文件夹和文件 extraResources: ['server/**/**'] // 指定打包 Server 到 Resource 文件夹中。 } } }
会将 server
文件夹打包到 Resources
文件夹中。为什么不打包大 app.asar
中呢?因为 .asar
文件是只读的,无法进行数据库的写入。
2、配置webpack
// vue.config.js configureWebpack: { externals: ['pg', 'sqlite3', 'tedious', 'pg-hstore'] }
3、创建 Electron 子进程
function createServerProcess() { if (!isDevelopment) { // 生产环境 serverProcess = fork('../server/index.js', [], { cwd: path.join(__dirname, '../server') }) } else { // 开发环境 serverProcess = fork(require.resolve('../server/index.js')) serverProcess.on('close', code => { console.log('子线程已经退出', code) }) } }
程序退出时,需要终止子进程 process.kill(serverProcess.pid)
至此:Mac可以启动服务和访问数据库
问题
windows 下无法启动服务 && Please install sqlite3
错误
-
在 Sequelize 中指定数据库的类型,默认有时无法读取到。
-
执行
cnpm i
命令安装依赖包,会自动对 sqlite 3进行编译,node_module/sqlite3/lib/binding
中可以看到文件。或者执行命令npm run postinstall
(管理员身份执行,npm i
会默认执行该命令) -
或者手动编译
npm rebuild
进行手动编译。 -
执行命令编译为 electron匹配的 sqlite3 文件。
node-gyp rebuild --target=6.1.0 --arch=x64 --target_platform=win32 --dist-url=https://npm.taobao.org/mirrors/node/ --module_name=node_sqlite3 --module_path=../lib/binding/electron-v6.1-win32-x64
- target 为 electron 版本,或者 node 版本
- –arch 架构;–traget_platform: 目标系统
- –dist-url: Header 文件下载地址
注:参考另一篇文中: Koa使用Sqlite3和Sequelize
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- 查看php-fpm开启的进程数以及每个进程的内存限制
- Laravel 使用 Supervisor 开启多个进程处理队列
- Swoole 启动一个服务,开启了哪些进程和线程?
- 【死磕 Spring】----- IOC 之解析 bean 标签:开启解析进程
- 用 dotTrace 进行性能分析时,Timeline 打不开?无法启动进程?也许你需要先开启系统性能计数器的...
- 进程:进程生命周期
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Algorithms Unlocked
Thomas H. Cormen / The MIT Press / 2013-3-1 / USD 25.00
Have you ever wondered how your GPS can find the fastest way to your destination, selecting one route from seemingly countless possibilities in mere seconds? How your credit card account number is pro......一起来看看 《Algorithms Unlocked》 这本书的介绍吧!