nw.js 打包方法

由 夕空 撰写于  2020年5月9日

一、常规打包nw.exe+app.nw

1.先将项目文件+package.json压缩为.zip,后改名为app.nw(使用Bandizip可自定义压缩app.nw)。
2.拷贝至nw.js程序目录内。
3.运行cmd命令:copy /b nw.exe+app.nw app.exe 即可生成exe执行文件。

写了个.bat批处理命令:

@echo off
cd %cd%/nwjs32 && del app.exe && copy /b nw.exe+app.nw app.exe && del app.nw
pause

nwjs32是批处理文件旁的nw.js程序文件夹

二、使用nwjs-builder-phoenix打包项目

全局安装:

npm i nwjs-builder-phoenix -g

package.json配置如下:

{
"name": "myapp",
"main": "index.html",
"version": "2.1.0",
"homepage": "http://",
"description": "项目说明",
"always-on-top": true,
"window": {
"title": "项目名",
"icon": "config/logo.png",
"position": "center",
"width": 1280,
"height": 720,
"toolbar": true,
"frame": true,
"transparent": false,
"resizable": true,
"min_width": 1000,
"fullscreen": false
},
"webkit": {
"plugin": true
},
"chromium-args": "--allow-file-access-from-files",
"chromium-args": "--disable-pinch",
"author": "jxh",
"license": "ISC",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dist": "build --tasks win-x86,linux-x86,mac-x64 --mirror https://npm.taobao.org/mirrors/nwjs/ .",
"start": "run --x86 --mirror https://npm.taobao.org/mirrors/nwjs/ ."
},
"build": {
"nwVersion": "0.41.3",
"targets": [
"zip",
"nsis7z"
]
},
"devDependencies": {
"nwjs-builder-phoenix": "^1.15.0"
}
}

然后在项目目录执行:

npm run dist

执行完后会在项目旁边新建dist目录,里面就是生成的最终文件,如果不需要zip压缩及exe安装包,可删除"targets"属性
此方法感觉最终只是把文件拷贝至执行程序目录,并生成exe执行文件及配置详细信息,但胜在打包方便。


声明:星耀夕空|版权所有,违者必究|如未注明,均为原创|本网站采用BY-NC-SA协议进行授权

转载:转载请注明原文链接 - nw.js 打包方法


欢迎光顾我的小站!