---
title: "nw 使用手记，用js 写桌面程序"
author: "hereson"
date: "2018-11-08T09:37:02Z"
tags: []
categories: ["Web前端"]
slug: "nw-js"
draft: false
lastmod: "2018-11-08T10:54:08Z"
id: 2433464
url: "https://hereson.iteye.com/blog/2433464"
---

安装 node.js , 将npm 添加至系统变量，下载 Git ，Git的bin目录路径添加至系统变量，如C:\\Program Files\\Git\\bin

新建一目录，nw,  目录下再建一目录 source

nw目录 建一文件 package.json（文件名）

{  
    "scripts": {  
        "dev": "nw /source/",  
        "prod": "nwbuild --platforms win32,win64 --buildDir dist1/ source/"  
    },  
    "devDependencies": {  
        "nw-builder": "^3.5.4"  
    }  
}

 

然后再在 source 目录下 建一文件 package.json（文件名）

{  
"name": "helloworld",  
"main": "index.html",  
"version": "0.1.0",  
    "description": "A simple SkyRTC demo",  
    "devDependencies": {  
        "grunt-nw-builder": "^3.1.0",  
        "nw-builder": "^3.5.1"  
    }  
}

同样在source 目录下 建一文件 index.html （文件名） 注：这个页面像网页一样是可以调用各种js的。。

&lt;!DOCTYPE html&gt;

&lt;html&gt;

  &lt;head&gt;

    &lt;title&gt;我的第一个js桌面程序&lt;/title&gt;

  &lt;/head&gt;

  &lt;body&gt;

    &lt;h1&gt;Hello World!&lt;/h1&gt;

  &lt;/body&gt;

&lt;/html&gt;

 

然后再

npm install nw-builder --save-dev

 

安装完成后再回到 nw 目录 执行

 

npm run prod

 

运行效果如下

 ![](http://dl2.iteye.com/upload/attachment/0131/0148/6ed64d7d-d799-3711-a6d6-5f376ff6c7da.png)