基于NestJS+Electron实现的桌面软件开发框架,让开发者能快速搭建一个使用Web技术开发桌面端应用软件的基础环境。
主进程是用esbuild构建的,主程序中集成了NestJS,并且基于NestJS集成了SQLite、LowDB等常用类库,让开发者可以像写NestJS后端一样编写自己的代码。
UI界面使用的Angular并集成了DevUI库,让开发者在编写UI界面时能使用与NestJS相同的语法,感觉这样的编码模式很酷。考虑到开发者的使用习惯,我也会延迟发布For Vue分支,同样集成DevUI库。
编译工具使用了更快速更轻量级的Vite,开发者可以使用“vite build”快速打包发布自己的应用程序。但遗憾的是目前@angular/cli还未支持Vite,使用For Angular分支需要先"ng"再"vite"。但你不用担心,只要ngc一旦支持vite,本框架也会第一时间同步更新。For Vue不会受到上述影响。
nodejs v16.x
npm v8.x
node-gyp v9.x
typescript >= v4.5.x <= v4.8.x
直接克隆此仓库
git clone https://gitee.com/sitdown-liu/nest-electron-dev.git
For Angular:
# 安装依赖包
yarn # npm install
# 运行开发模式
yarn dev:ng # npm run dev:ng
yarn dev:ne # npm run dev:ne
# 发布
yarn build:ng # npm run build:ng
yarn build:ne # npm run build:ne
For Vue
# 安装依赖包
yarn # npm install
# 运行开发模式
yarn dev # npm run dev
# 发布
yarn build # npm run build
与pnpm
一起使用,你需要调整你的.npmrc
node-linker=hoisted
public-hoist-pattern=*
shamefully-hoist=true
SQLite3安装/编译失败
使用electron开发桌面程序,sqlite编译最容易出错,你需要提前安装好Python2.7(下载地址)和vs2015(下载地址),然后执行以下操作:
#安装Windows的相关环境
npm install --global --production windows-build-tools
#安装node-gyp
npm install -g node-gyp
#安装并构建兼容electron的sqlite
npm install sqlite3 --build-from-source --runtime=electron --target=21.1.0 --dist-url=https://electronjs.org/headers
如果安装失败也许是你所在的网段被墙了,你可以使用网络代理、国内镜像或cnpm。
如果在.\node_moudles\sqlite3\lib\binding\
下多了一个electron-v3.1-win32-x64
文件夹,其下名为‘node_sqlite3.node’
的文件就是electron所需要的sqlite文件,到这里就已经安装完成了。
你也可以尝试手动构建支持electron的sqlite文件
#在package.json中添加脚本
"scripts": {
"postinstall": "electron-builder install-app-deps",
"rebuild": "electron-rebuild -f -w sqlite3"
},
#执行脚本
npm run postinstall
npm run rebuild
在Windows平台上安装和编译SQLite3会碰到一些奇怪的程序异常,以上纯粹个人经验,你还可以在SQLite3 bindings for NodeJS寻找其他解决方案。
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。