Taro入门——taro-application-template项目运行

环境准备

node环境(≥8.0.0)

taro环境安装

1、安装taro:
# 使用 npm 安装 cli
$ npm install -g @tarojs/cli

# 使用 yarn 安装 cli
$ yarn global add @tarojs/cli

# 使用 cnpm 安装 cli
$ cnpm install -g @tarojs/cli

注意:如果安装过程出现sass相关的安装错误,请在安装mirror-config-china后重试。

# 使用 npm
$ npm install -g mirror-config-china

# 使用 yarn 
$ yarn global add mirror-config-china

# 使用 cnpm
$ cnpm install -g mirror-config-china

出现 taro 不是内部或外部命令,也不是可运行的程序 或批处理文件。解决方案:
1)通过 yarn 安装的,查找yarn安装目录;把安装目录添加到系统环境变量中,重新打开终端即可
首先终端运行命令yarn global bin ,

# 查找yarn安装目录
$ yarn global bin 

2)尝试清除缓存,然后重新安装

npm cache vidify
2、安装项目依赖:
# 使用 npm 安装依赖
$ npm install

# 使用 yarn 安装依赖
$ yarn

# 使用 cnpm 安装依赖
$ cnpm install
3、运行项目:
# 使用 npm
$ npm run dev:rn
$ npm run build:rn

# 使用 yarn
$ yarn dev:rn
$ yarn build:rn

# 使用 taro (仅限全局安装)
$ taro build --type rn --watch
$ taro build --type rn

# npx 用户也可以使用
$ npx taro build --type rn--watch
$ npx taro build --type rn
启动完成

编译完成之后若无异常会自动打开一个终端,并在 8081 端口启动 Metro Bundler 负责打包 jsbundle。
注意:少数电脑上,可能不会 自动打开一个终端,可以手动启动,命令如下:

node ./node_modules/react-native/local-cli/cli.js start --reset-cache

这时可以打开: http://localhost:8081/ 可以查看是否启动成功。

Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐