Weex 環境搭建(win7),weex環境搭建win7
安裝 Node.js安裝 weex-toolkit
安裝好node.js後,開啟CMD工具現在安裝weex-toolkit,這是weex的Integration Environment。
npm install -g weex-toolkit
有了weex-toolkit就可以使用weex命令了
我使用的版本是,這個可能變化的很快
先看一下weex命令
Usage: weex foo/bar/we_file_or_dir_path [options]Usage: weex debug [options] [we_file|bundles_dir]Usage: weex init Options: --qr display QR code for PlaygroundApp [boolean] --smallqr display small-scale version of QR code for PlaygroundApp,try it if you use default font in CLI [boolean] -o, --output transform weex we file to JS Bundle, output path must specified (single JS bundle file or dir) [for create sub cmd]it specified we file output path [default: "no JSBundle output"] --watch using with -o , watch input path , auto run transform if change happen -s, --server start a http file server, weex .we file will be transforme to JS bundle on the server , specify local root path using the option [string] --port http listening port number ,default is 8081 [default: -1] --wsport websocket listening port number ,default is 8082 [default: -1] --np do not open preview browser automatic [boolean] -f, --force [for create sub cmd]force to replace exsisting file(s) [boolean] -h, --host [default: "127.0.0.1"] weex debug -h for Weex debug help information. for cmd example & more information please visithttps://www.npmjs.com/package/weex-toolkit
如果你只是想調試某個we檔案,那麼執行weex xxx.we即可以運行在本地瀏覽器中,當然如果執行
weex test.we --qr -h
--qr 即是顯示本地地址檔案的二維碼,安裝playground後既可以掃描二維碼看到we檔案的頁面。
-h 是熱更新,當然只對瀏覽器有效
初始化項目hello weex
先建立一個app檔案夾,我是這個目錄D:\webxm\nodejs\weex-test
然後使用cmd進入weex-text這個目錄,或者在這個目錄直接開啟cmd(按住shift鍵同時點擊滑鼠右鍵選擇【在此處開啟命令視窗】)
執行如下命令
按下斷行符號鍵出現如下資訊
file: .gitignore created.file: README.md created.file: index.html created.file: package.json created.file: src/main.we created.file: webpack.config.js created.
接著安裝依賴
npm install
現在我們建立了一個目錄,然後並且在這裡初始化了一個weex-test項目。
目錄結構圖
src-代碼目錄
index-瀏覽器啟動頁面
webpack.config.js-webpack的設定檔
觀察package.json裡面有這樣四個命令
{ "name": "weex-test", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "build": "webpack", "dev": "webpack --watch", "serve": "serve -p 8080", "test": "echo \"Error: no test specified\" && exit 1" },
改成如下(8080連接埠可以隨便改)
{"name": "weex-test","version": "1.0.0","description": "","main": "index.js","scripts": {"build": "webpack","dev": "webpack & serve -p 8080","test": "echo \"Error: no test specified\" && exit 1"},
現在試試啟動這個項目
npm run dev
現在瀏覽器訪問一下localhost:8080會出現如下介面
好了,現在我們已經啟動起來了這個項目。
另一種啟動方式
先進入src工作目錄,運行對應的we檔案,命令如下
weex xxx.we
我啟動並執行檔案是這個
你系統預設瀏覽器的視窗將自動開啟並且顯示Hello Weex!
傳送門:weex 真機調試二維碼