Weex開發實踐(一)嵌入Weex到你的iOS工程
阿新 • • 發佈:2019-02-20
第一步:建立一個Weex專案
假設你已經搭建好了Weex開發環境,安裝了weex-tools。在terminal執行
weex create awesome-project
執行完命令後,在 awesome-project 目錄中就建立了一個使用 Weex 和 Vue 的模板專案。
然後執行:
weex platform add ios
之後在工程中生成了iOS模板,找到platforms目錄下對應模板工程,將裡面的demo程式碼拷貝到我們自己的iOS工程,包括WeexConfig、WeexScanner檔案,其中index.js就是通過weex編譯生成的執行檔案。
第二步:新增依賴
使用Cocoapods,在Podfile檔案中加入如下內容
source '[email protected]:CocoaPods/Specs.git'
target 'YourTarget' do
platform :ios, '7.0'
pod 'WeexSDK', '0.17.0' ## 建議使用WeexSDK新版本
end
開啟terminal,在Podfile檔案路徑下執行pod install 命令安裝WeexSDK。
安裝後,執行工程我們就能看到Weex的歡迎介面了。
第三步:生成index.js檔案
使用 weex compile 命令可以編譯單個weex檔案或者整個資料夾中的weex檔案。
$ weex compile [source] [dist] [options]
在index.vue對應的路徑下可以這樣使用
weex compile index.vue dist
編譯器自動生成的dist資料夾裡包含了index.js檔案,把iOS工程中的 index.js檔案替換,然後編譯執行成功。