Taro官网

taro环境搭建
  1. 在任意位置新建一个文件夹
  2. 在vscode中打开文件夹
  3. 安装taro
taro安装方式:
1、yarn global  add @tarojs/cli
使用yarn安装
2、cnpm  install -g @tarojs/cli
使用cnpm安装
3、npm install -g @tarojs/cli
使用npm安装  这里不建议使用
win10安装yarn
Get-ExecutionPolicy
出现:Restricted  进行下一步 
Set-ExecutionPolicy AllSigned 或者 Set-ExecutionPolicy Bypass -Scope Process
输入:y
输入:choco install yarn 安装
使用yarn安装时会出现的问题
PS H:\前端框架学习\taro> yarn global add @tarojs/cli
yarn : 无法加载文件 D:\chengxuyingyong\node\node_global\yarn.ps1,因为在此系统上禁止运行脚本。有关详细信息,请参阅 https:/go.microsoft.com/fwlink/?L
inkID=135170 中的 about_Execution_Policies。
所在位置 行:1 字符: 1
+ yarn global add @tarojs/cli
+ ~~~~
    + CategoryInfo          : SecurityError: (:) [],PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess
解决方案

在搜索框中数据powershell,并以管理员的身份打开

输入以下3条命令:
set-ExecutionPolicy RemoteSigned
y
get-ExecutionPolicy

详细看下面代码

第一步:搜索powershell
在这里插入图片描述
第二步:

Windows PowerShell
版权所有 (C) Microsoft Corporation。保留所有权利。

PS C:\Users\Administrator> set-ExecutionPolicy RemoteSigned

执行策略更改
执行策略可帮助你防止执行不信任的脚本。更改执行策略可能会产生安全风险,如 https:/go.microsoft.com/fwlink/?LinkID=135170
中的 about_Execution_Policies 帮助主题所述。是否要更改执行策略?
[Y] 是(Y)  [A] 全是(A)  [N] 否(N)  [L] 全否(L)  [S] 暂停(S)  [?] 帮助 (默认值为“N”): y
PS C:\Users\Administrator> get-ExecutionPolicy
RemoteSigned
PS C:\Users\Administrator>

问题解决之后再去vscode编辑器中,在终端中输入

yarn global add @tarojs/cli
安装过程
PS H:\前端框架学习\taro> yarn global add @tarojs/cli
yarn global v1.22.4
[1/4] Resolving packages...
warning @tarojs/cli > chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
warning @tarojs/cli > eslint-plugin-typescript@0.12.0: Deprecated: Use @typescript-eslint/eslint-plugin instead
warning @tarojs/cli > fbjs > core-js@2.6.11: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
warning @tarojs/cli > babel-core > babel-register > core-js@2.6.11: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
warning @tarojs/cli > babel-core > babel-runtime > core-js@2.6.11: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
warning @tarojs/cli > npm-check > execa > cross-spawn-async@2.2.5: cross-spawn no longer requires a build toolchain, use it instead
warning @tarojs/cli > stylelint > file-entry-cache > flat-cache > circular-json@0.3.3: CircularJSON is in maintenance only, flatted is its successor.[2/4] Fetching packages...
info fsevents@1.2.13: The platform "win32" is incompatible with this module.
info "fsevents@1.2.13" is an optional dependency and failed compatibility check. Excluding it from installation.
info fsevents@2.1.3: The platform "win32" is incompatible with this module.
info "fsevents@2.1.3" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning "@tarojs/cli > @tarojs/helper > @tarojs/taro@2.2.7" has unmet peer dependency "nervjs@^1.5.0".
warning "@tarojs/cli > @typescript-eslint/parser > @typescript-eslint/typescript-estree > tsutils@3.17.1" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta".
[4/4] Building fresh packages...
success Installed "@tarojs/cli@2.2.7" with binaries:
      - taro
Done in 104.03s.
PS H:\前端框架学习\taro>

安装成功之后检查一下

输入:taro -- varsion
PS H:\前端框架学习\taro> taro --version
� Taro v2.2.7
2.2.7
PS H:\前端框架学习\taro>
成功

创建第一个项目

命令:taro init tarodemo1

#创建一个项目  tarodemo1 这是项目名称
PS H:\前端框架学习\taro>  taro  init tarodemo1
� Taro v2.2.7

Taro 即将创建一个新项目!
Need help? Go and open issue: https://github.com/NervJS/taro/issues/new

√ 拉取远程模板仓库成功!
#项目介绍自己随便填 :taro学习
? 请输入项目介绍! taro学习
#这里是根据你的需要进行选择 
? 是否需要使用 TypeScript ? No
#这里是选择预编译器,根据项目或者个人需求进行选择
? 请选择 CSS 预处理器(Sass/Less/Stylus) Less
? 请选择模板 默认模板

创建的时间可能有点长 耐心等待一下


Build failed with error code: 1

    at ChildProcess.exithandler (child_process.js:295:12)
    at ChildProcess.emit (events.js:210:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5) {
  killed: false,
  code: 1,
  signal: null,
  cmd: 'yarn install'
}
创建项目 tarodemo1 成功!
请进入项目目录 tarodemo1 开始工作吧!�
安装相关依赖
使用 yarn 安装依赖
yarn
使用 cnpm 安装依赖
cnpm install
使用 npm 安装依赖
npm install

启动项目

npm run dev:h5
//微信小程序
npm run dev:weapp
//百度小程序
npm run dev:swan
//支付宝小程序
npm run dev:alipay
//字节跳动小程序 
npm run dev:tt

启动成功后会自动弹出新页面,显示hello word到这里就创建成功了

Logo

智屏生态联盟致力于大屏生态发展,利用大屏快应用技术降低开发者开发、发布大屏应用门槛

更多推荐