weex 安装、创建项目并在iOS模拟器中运行
安装npm,百度会告诉你各种姿势安装
安装 weex
$ npm install -g weex-toolkit
如果安装过程中出现等待时间过长的情况,请设置一下npm的代理
$ npm config set registry https://registry.npm.taobao.org $ npm config list
出现如下显示表示 weex 安装成功
+ weex-toolkit@1.3.4 updated 1 package in 24.354s
创建 weex 项目
$ weex create firstWeexApp
这一步会让你填写项目名、描述、作者等信息,按着提示写就行
需要注意的选项
- Use ESLint to lint you code ? 据说校验比较严格,我选的是No
- npm or yarn 的选项就选 npm 就行
这就完成了吗 ?对于安装过 phantomjs 的用户是的,但对于第一次玩 weex 的朋友们来讲会出现如下提示:
PhantomJS not found on PATH
Downloading https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-macosx.zip
Saving to /var/folders/cw/4mqt3r156j30shm3x91dyd9c0000gn/T/phantomjs/phantomjs-2.1.1-macosx.zip
Receiving...
[====------------------------------------] 9%
没开 vpn 的话你就在这儿等吧,我是等了很久
在 iOS模拟器中运行
执行 npm install 可能会出现如下提示
npm WARN ajv-keywords@3.1.0 requires a peer of ajv@^6.0.0 but none is installed. You must install peer dependencies yourself. npm WARN babel-loader@6.4.1 requires a peer of webpack@1 || 2 || ^2.1.0-beta || ^2.2.0-rc but none is installed. You must install peer dependencies yourself. npm WARN babel-loader@6.4.1 requires a peer of webpack@1 || 2 || ^2.1.0-beta || ^2.2.0-rc but none is installed. You must install peer dependencies yourself.
只需要按着提示进行安装就可以,如:
$ npm install ajv $ npm install babel $ npm install webpack
使用 weex platform list 命令查看你的项目中支持的平台
$ weex platform list Installed platforms: - ios 4.1.6 Available platforms: - android ^6.3.8
如果没有出现 iOS 的支持平台请执行 weex platform add ios ,出现如下提示
$ weex platform add ios 18:01:32 : Adding ios weexpack-ios@4.1.6 ... 18:01:32 : Success!
运行 iOS 项目
$ weex run ios ... (一堆提示信息) ... /bin/sh: pod: command not found 18:01:56 : Command run error, please check if there has the same issue here: https://github.com/weexteam/weex-toolkit/issues/337 18:01:56 : Error:Error: Command failed: pod update /bin/sh: pod: command not found
安装 pod
$ sudo gem install -n /usr/local/bin cocoapods
安装成功后再次运行 weex run ios 出现 iOS 模拟器,并显示默认页面