1. 介绍
nw.js
为打包工具
express
当服务器
html
当界面
2. 安装配置步骤
第一步: 创建一个文件夹 webapp
第二步:安装依赖
初始化
npm init
安装 express
npm install -g express-generator
express
目录结构
create : public\
create : public\javascripts\
create : public\images\
create : public\stylesheets\
create : public\stylesheets\style.css
create : routes\
create : routes\index.js
create : routes\users.js
create : views\
create : views\error.jade
create : views\index.jade
create : views\layout.jade
create : app.js
create : package.json
create : bin\
create : bin\www
安装 nw.js 运行 和 打包依赖
npm install nwjs-builder-phoenix --save-dev
第三步: 把html文件夹
放入public文件夹下面
3. 修改文件重点部分
第一步:修改package.json
文件
{
"name": "webapp",
"version": "0.0.0",
"node-main":"./bin/www",
"main": "http://localhost:3000/html/index.html",
"private": true,
"window": {
"title": "这是一个界面",
"icon": "./public/html/favicon.ico",
"width": 1920,
"height": 1080,
"toolbar": false,
"frame": true,
"resizable": true,
"position": "center",
"transparent": false,
"show_in_taskbar": true,
"show": true
},
"node-remote": "*://*",
"scripts": {
"starts": "node ./bin/www",
"dist": "build --tasks win-x86,win-x64,linux-x86,linux-x64,mac-x64 --mirror https://npm.taobao.org/mirrors/nwjs/ .",
"start": "run --x86 --mirror https://npm.taobao.org/mirrors/nwjs/ ."
},
"build": {
"nwVersion": "0.56.1"
},
"dependencies": {
"cookie-parser": "~1.4.4",
"debug": "~2.6.9",
"express": "~4.16.1",
"http-errors": "~1.6.3",
"jade": "~1.11.0",
"morgan": "~1.9.1"
},
"devDependencies": {
"nwjs-builder-phoenix": "^1.15.0"
}
}
主要部分
:这两行代码
"node-main":"./bin/www", // 不要有空格
"main": "http://localhost:3000/html/index.html",
4.运行 和 打包
1. exe运行
npm run start
2.打包成exe
npm run dist
打包完成会在项目目录下dist
文件夹内