加载中...

Weex 环境搭建(win7)


安装 Node.js

  1. node.js需要4.0+
  2. 百度云下载地址http://pan.baidu.com/s/1o84g6c6
  3. 官网下载地址https://nodejs.org/en/
  4. 安装教程请看这里node.js安装图解

安装 weex-toolkit

安装好node.js后,打开CMD工具现在安装weex-toolkit,这是weex的集成环境。

  1. npm install -g weex-toolkit

有了weex-toolkit就可以使用weex命令了

我使用的版本是如图,这个可能变化的很快


先看一下weex命令

  1. Usage: weex foo/bar/we_file_or_dir_path  [options]
  2. Usage: weex debug [options] [we_file|bundles_dir]
  3. Usage: weex init
  4.  
  5. Options:
  6.   --qr          display QR code for PlaygroundApp                      [boolean]
  7.  
  8.   --smallqr     display small-scale version of QR code for PlaygroundApp,try it
  9.                 if you use default font in CLI                         [boolean]
  10.  
  11.   -o, --output  transform weex we file to JS Bundle, output path must specified
  12.                 (single JS bundle file or dir)
  13.                 [for create sub cmd]it specified we file output path
  14.                                                  [default: "no JSBundle output"]
  15.  
  16.   --watch       using with -o , watch input path , auto run transform if change
  17.                 happen
  18.   -s, --server  start a http file server, weex .we file will be transforme to JS
  19.  
  20.                 bundle on the server , specify local root path using the option
  21.                                                                         [string]
  22.  
  23.   --port        http listening port number ,default is 8081        [default: -1]
  24.  
  25.   --wsport      websocket listening port number ,default is 8082   [default: -1]
  26.  
  27.   --np          do not open preview browser automatic                  [boolean]
  28.  
  29.   -f, --force   [for create sub cmd]force to replace exsisting file(s) [boolean]
  30.  
  31.   -h, --host                                              [default: "127.0.0.1"]
  32.  
  33.  
  34. weex debug -h for Weex debug help information.
  35.  
  36. for cmd example & more information please visit
  37. https://www.npmjs.com/package/weex-toolkit
如果你只是想调试某个we文件,那么执行weex xxx.we即可以运行在本地浏览器中,当然如果执行
  1. weex test.we --qr -h
--qr 即是显示本地地址文件的二维码,安装playground后既可以扫描二维码看到we文件的页面。
-h 是热更新,当然只对浏览器有效

初始化项目hello weex

先建立一个app文件夹,我是这个目录D:\webxm\nodejs\weex-test

然后使用cmd进入weex-text这个目录,或者在这个目录直接打开cmd(按住shift键同时点击鼠标右键选择【在此处打开命令窗口】)

执行如下命令

按下回车键出现如下信息


  1. file: .gitignore created.
  2. file: README.md created.
  3. file: index.html created.
  4. file: package.json created.
  5. file: src/main.we created.
  6. file: webpack.config.js created.
接着安装依赖
  1. npm install

现在我们创建了一个目录,然后并且在这里初始化了一个weex-test项目。

目录结构图

src-代码目录
index-浏览器启动页面
webpack.config.js-webpack的配置文件
观察package.json里面有这样四个命令

  1. {
  2.   "name": "weex-test",
  3.   "version": "1.0.0",
  4.   "description": "",
  5.   "main": "index.js",
  6.   "scripts": {
  7.     "build": "webpack",
  8.     "dev": "webpack --watch",
  9.     "serve": "serve -p 8080",
  10.     "test": "echo \"Error: no test specified\" && exit 1"
  11.   },
改成如下(8080端口可以随便改)
  1. {
  2. "name": "weex-test",
  3. "version": "1.0.0",
  4. "description": "",
  5. "main": "index.js",
  6. "scripts": {
  7. "build": "webpack",
  8. "dev": "webpack & serve -p 8080",
  9. "test": "echo \"Error: no test specified\" && exit 1"
  10. },
现在试试启动这个项目
  1. npm run dev

现在浏览器访问一下localhost:8080会出现如下界面


好了,现在我们已经启动起来了这个项目。

另一种启动方式

先进入src工作目录,运行对应的we文件,命令如下

  1. weex xxx.we
我运行的文件是这个

你系统默认浏览器的窗口将自动打开并且显示Hello Weex!


第 1-3 条, 共 3 条.
pguan 2017-03-12 21:51:39
好教材,支持一个回复
orange 2017-02-14 11:04:30
怎么运行weex的demo回复
zhangwei 2016-12-13 16:42:04
正在学习,好教程回复