第一步:创建一个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 'git@github.com: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文件替换,然后编译运行成功。