node-webkit 桌面开发 初入1

时间:2022-07-25 05:44:52

node-webkit  是什么就不介绍了

注意官网的一句话 ”node-webkit is based on Chromium and node.js " 所以node-webkit 实际是嵌套了个Chromium 浏览器 ,而不是webkit内核。

 

1项目目录,配置 package.json

{
"main": "main.html", /* APP的主入口,文件名任意;必选 */
"name": "demo", /* APP的名称,必须具备唯一性,且符合正常变量命名;必选 */
"single-instance":false, /*(boolean)是否只允许启动单个实例,true为只允许一个软件实例运行。默认是true*/
"description": "demo app of node-webkit", /* APP的简单描述 */
"version": "0.1.0", /* APP的版本号 */
"keywords": [ "demo", "node-webkit" ], /* APP的关键字,搜索APP时用到 */
"window": { /* APP的窗口属性 */
"title":"", /*(string)窗口标题 如果index.html 有title标题默认使用index的title*/
"icon": "link.png", /* APP图标(windows下,状态栏上可见) */
"toolbar": false, /* 是否显示工具栏 */
"width": 800, /* 窗口初始化大小 */
"height": 500,
"max_width":1000, /*设置软件最大宽度*/
"max_height":800, /*设置软件最大高度*/
"position":"center", /* null:默认 , center :软件启动在中间显示 , mouse:软件启动在鼠标指标位置显示。*/
"resizable":true, /*设置窗口是否可以调整大小*/
"frame": true, /* 是否显示外窗体,如最大化、最小化、关闭按钮 */
"show_in_taskbar":true /*是否在任务栏显示图标*/
},
"user-agent": "%name %ver %nwver %webkit_ver %osinfo" /* 可自定义APP的UA */
}

 

 

2开发调试,直接将项目目录 拖到nw.exe 上就可以了

3 打包

 window 下 :将项目目录压内的文件压缩合并成zip文件 注意不能直接压缩文件夹目录。

copy /b nw.exe+ga.zip app.exe 生成app.exe

要注意的是即使 在node-webkit  10.5  修复了,跳转页面时不清理内存造成应用崩溃的问题,但是不能直接使用网络地址配置成app的入口文件("main": "http://localhost:8882/app/marketing/index.html#/view/marketActivity",),

这样切换时也会经常出现应用崩溃。 

入口文件必须是个本地文件    "main": "index.html",再在index.html 做location.href  的跳转。