0
点赞
收藏
分享

微信扫一扫

node-webkit学习(1)hello world


node-webkit解决了我通过htmljs来编写桌面应用的难题

至于node-webkit的定义,按照作者的说法:

“ 基于node.js和chromium的应用程序实时运行环境,可运行通过HTML(5)、CSS(3)、Javascript来编写的本地应用程序。node.js和webkit的结合体,webkit提供DOM操作,node.js提供本地化操作;且将二者的context完全整合,可在HTML代码中直接使用node.js的API。”

node-webkit学习(1)hello world_javascript

 


1.1  环境安装


webkit是开源项目,项目地址为​​https://github.com/rogerwang/node-webkit​​。

我们可以在该项目首页找到downloads节(​​https://github.com/rogerwang/node-webkit#downloads​​),该处提供了预编译版本:

Prebuilt binaries (v0.9.2 - Feb 20, 2014):

· Linux: ​​32bit​​​ / ​64.tar.gz">​64bit​​

· Windows: ​​win32​​

· Mac: ​​32bit, 10.7+​​


1.1.1 WINDOWS下的安装


下载windows版本的安装包,解压到磁盘。

node-webkit学习(1)hello world_json_02

双击nw.exe,出现如下界面:

node-webkit学习(1)hello world_ViewUI_03


1.1.2  LINUX环境下的安装


以ubuntu为例,首先下载安装包。


wget ​​http://dl.node-webkit.org/v0.8.5/node-webkit-v0.8.5-linux-ia32.tar.gz​​


 

node-webkit学习(1)hello world_node.js_04

解压:


tar -xzf node-webkit-v0.8.5-linux-ia32.tar.gz


node-webkit学习(1)hello world_html_05

node-webkit学习(1)hello world_javascript_06

运行nw,看是否正常。

node-webkit学习(1)hello world_ViewUI_07

我出现

./nw: error while loading shared libraries: libudev.so.0: cannot open shared object file: No such file or directory

的错误。可以按如下方式解决:

1)下载安装ghex:sudo apt-get install ghex

node-webkit学习(1)hello world_ViewUI_08

2)在nw可执行文件目录中用ghex打开nw:

ghex  nw

node-webkit学习(1)hello world_html_09

 

3)在ghex中,ctrl+f,打开搜索工具,查找libudev.so.0。

node-webkit学习(1)hello world_node.js_10

关闭搜索框,在右侧字符窗口,修改0为1。

node-webkit学习(1)hello world_node.js_11

4)ctrl+s保存后退出ghex,现在再打开nw就会看到一个小窗口了,这就成功了。

node-webkit学习(1)hello world_json_12


1.2 HELLO WORLD


 

对新的运行时的尝试,往往都是从经典的hello world开始,本人也不免落俗。

先新建一个helloWorld目录,存放相关文件。

node-webkit学习(1)hello world_json_13

先创建helloWorld.html文件,内容如下(来自作者的示例):


<!DOCTYPE html>
<html>
<head>
<title>Hello World!</title>
</head>
<body>
<h1>Hello World!</h1>
<script>document.write(process.version)</script>.
</body>
</html>


node-webkit学习(1)hello world_node.js_14

下一步,创建package.json文件:


{
"name": "helloworld",
"main": "helloworld.html"
}


node-webkit学习(1)hello world_javascript_15

第三步,将helloworld.html和package.json打包到一个zip文件包中。

node-webkit学习(1)hello world_ViewUI_16

下面我们使用nw来执行压缩包。


./nw ../helloword/hello.nw


node-webkit学习(1)hello world_html_17

举报

相关推荐

0 条评论