[Taro] 5分钟快速新起一个Taro项目,并上传github

284 阅读1分钟

5分钟快速新起一个Taro项目,并上传github。
之前也是踩了很多坑,实践了无数次,现在初始化一个新项目的速度快的嘎嘎嘎。

Let's go!

node环境:v.16.14.0

Taro 局部安装

不喜欢在全局安装 @taro/cli,所以先查看下全局有安装过哪些安装包:npm list -g --dept 0,避免后期安装过程中遇到不必要的版本不匹配的问题。

全局如果有安装过,可以使用 yarn global remove @tarojs/cli 卸载。

使用官网提供的局部安装的方式,npm 5.2+ 可在不全局安装的情况下使用 npx 创建模板项目:
npx @tarojs/cli init mini

因为 taro 3.6.8 还有些配置问题没修复,我先用3.6.7版本进行安装:
npx @tarojs/cli@3.6.7 init taro-template

如图所示: image.png

安装成功后:cd taro-template & yarn

将本地项目上传github

新建远程仓库时,记得不要勾选Add a README file选项,不然会遇到推送代码报错的坑。

image.png

image.png

新建好后如图:

image.png

回到我们的项目命令行中依次执行:

git init
git add ./
git commit -m 'init'
git remote add origin https://github.com/xxx/taro-template.git
git branch -M main
git push -u origin main

image.png

项目推送成功后,刷新github可以看到我们的本地项目已经上传至远程仓库了,真棒:

image.png

修改项目中的config配置的输出目录:

outputRoot: `dist/${process.env.TARO_ENV}`

然后本地运行:yarn dev:weappyarn dev:alipay

分别用微信开发者工具和支付宝开发者工具,打开编译产物dist/weappdist/alipay

image.png

image.png

恭喜你!已经搭建成功了一个跨端小程序项目!