Weex入門篇——Mac 安裝Weex


相關文檔:http://blog.csdn.net/jasonblog/article/details/51863173

 

前言

相比較於React Native的“Learn once, write anywhere”,Weex的口號是“Write once, run everywhere”。考慮到React Native比較任性的向下兼容性,我們也引入了Weex做一番了解。

一、Weex 環境配置

  1、參考官方教程,我們需要先安裝Node。在Mac上也可以通過Homebrew直接進行安裝:brew install node。(這里趕腳)

接着我們需要安裝Weex CLI:npm install -g weex-toolkit,並確保版本號大於0.1.0:

    1. $ weex —version

    2. v1.0.4  (說明安裝成功)

  【備注:如果在執行 npm install -g weex-toolkit 時,安裝weex tookit老是失敗的解決辦法:使用淘寶的鏡像來安裝;

  sudo npm install -g weex-toolkit@1.0.4 --registry=https://registry.npm.taobao.org    

  這時如果出現:

  we suggest you run "sudo chmod 777 ~" and re installor you can try "mkdir ~/.xtoolkit&&chmod 777 .xtoolkit"  則說明是權限問題。

  執行如下權限命令:

  1、 cd  /Users/enniu/.xtoolkit  (這里是我自己的絕對路徑)

  2、sudo chmod 777 ~

  (或者cd /Users/enniu/,然后執行chmod 777 .xtoolkit)】

至此,准備工作已經到位,我們可以開始編寫Weex程序了。 

    2、開始執行weex 部署

     創建一個名為helloweex.we的文件,並編寫以下代碼:

<template>

  <div>

   <text>Hello Weex</text>

   </div>

</template>   

通過命令行在helloweex.we文件所在的目錄下執行如下命令:

 $ weex helloweex.we

info Wed May 03 2017 16:43:54 GMT+0800 (CST)WebSocket  is listening on port 8082 

info Wed May 03 2017 16:43:54 GMT+0800 (CST)http  is listening on port 8081 

info http://192.168.20.108:8081/?hot-reload_controller&page=helloweex.js&loader=xhr&wsport=8082&type=we

說明成功

【備注:如果出現如下

Error: EACCES: permission denied, unlink '/Users/enniu/.weex_tmp/weex.html'

    at Object.fs.unlinkSync (fs.js:1081:18) 

 則需說明讀寫權限沒有,執行下面兩句即可

   1、cd /Users/enniu/

   2、sudo chmod 777 .weex_tmp/】

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM