99re热这里只有精品视频,7777色鬼xxxx欧美色妇,国产成人精品一区二三区在线观看,内射爽无广熟女亚洲,精品人妻av一区二区三区

Taro 安裝及使用

2021-09-30 17:06 更新

安裝

Taro 項目基于 node,請確保已具備較新的 node 環(huán)境(?>=8.0.0?),推薦使用 node 版本管理工具 nvm 來管理 node,這樣不僅可以很方便地切換 node 版本,而且全局安裝時候也不用加 sudo 了。

CLI 工具安裝

首先,你需要使用 npm 或者 yarn 全局安裝?@tarojs/cli?,或者直接使用?npx?:

  1. # 使用 npm 安裝 CLI
  2. $ npm install -g @tarojs/cli@next
  3. # OR 使用 yarn 安裝 CLI
  4. $ yarn global add @tarojs/cli@next
  5. # OR 安裝了 cnpm,使用 cnpm 安裝 CLI
  6. $ cnpm install -g @tarojs/cli@next

注意事項

值得一提的是,如果安裝過程出現(xiàn)?sass?相關(guān)的安裝錯誤,請在安裝?m?irror-config-china??后重試。

  1. $ npm install -g mirror-config-china

項目初始化

使用命令創(chuàng)建模板項目

  1. $ taro init myApp

npm 5.2+ 也可在不全局安裝的情況下使用 npx 創(chuàng)建模板項目

  1. $ npx @tarojs/cli init myApp

taro init myApp command screenshot

在創(chuàng)建完項目之后,Taro 會默認開始安裝項目所需要的依賴,安裝使用的工具按照 yarn>cnpm>npm 順序進行檢測,一般來說,依賴安裝會比較順利,但某些情況下可能會安裝失敗,這時候你可以在項目目錄下自己使用安裝命令進行安裝

  1. # 使用 yarn 安裝依賴
  2. $ yarn
  3. # OR 使用 cnpm 安裝依賴
  4. $ cnpm install
  5. # OR 使用 npm 安裝依賴
  6. $ npm install

進入項目目錄開始開發(fā),目前已經(jīng)支持 微信/百度/支付寶/字節(jié)跳動/QQ 小程序、H5、快應用以及 ReactNative 等端的代碼轉(zhuǎn)換,針對不同端的啟動以及預覽、打包方式并不一致

運行

Taro 需要運行不同的命令,將 Taro 代碼編譯成不同端的代碼,然后在對應的開發(fā)工具中查看效果。

image

微信小程序

選擇微信小程序模式,需要自行下載并打開微信開發(fā)者工具,然后選擇項目根目錄進行預覽。

微信小程序編譯預覽及打包(去掉 ?—watch ?將不會監(jiān)聽文件修改,并會對代碼進行壓縮打包)

  1. # yarn
  2. $ yarn dev:weapp
  3. $ yarn build:weapp
  4. # npm script
  5. $ npm run dev:weapp
  6. $ npm run build:weapp
  7. # 僅限全局安裝
  8. $ taro build --type weapp --watch
  9. $ taro build --type weapp
  10. # npx 用戶也可以使用
  11. $ npx taro build --type weapp --watch
  12. $ npx taro build --type weapp

百度小程序

選擇百度小程序模式,需要自行下載并打開百度開發(fā)者工具,然后在項目編譯完后選擇項目根目錄下 dist 目錄進行預覽。

百度小程序編譯預覽及打包(去掉 ?—watch? 將不會監(jiān)聽文件修改,并會對代碼進行壓縮打包)

  1. # yarn
  2. $ yarn dev:swan
  3. $ yarn build:swan
  4. # npm script
  5. $ npm run dev:swan
  6. $ npm run build:swan
  7. # 僅限全局安裝
  8. $ taro build --type swan --watch
  9. $ taro build --type swan
  10. # npx 用戶也可以使用
  11. $ npx taro build --type swan --watch
  12. $ npx taro build --type swan

支付寶小程序

選擇支付寶小程序模式,需要自行下載并打開支付寶小程序開發(fā)者工具,然后在項目編譯完后選擇項目根目錄下 dist 目錄進行預覽。

支付寶小程序編譯預覽及打包(去掉 ?—watch? 將不會監(jiān)聽文件修改,并會對代碼進行壓縮打包)

  1. # yarn
  2. $ yarn dev:alipay
  3. $ yarn build:alipay
  4. # npm script
  5. $ npm run dev:alipay
  6. $ npm run build:alipay
  7. # 僅限全局安裝
  8. $ taro build --type alipay --watch
  9. $ taro build --type alipay
  10. # npx 用戶也可以使用
  11. $ npx taro build --type alipay --watch
  12. $ npx taro build --type alipay

字節(jié)跳動小程序

選擇字節(jié)跳動小程序模式,需要自行下載并打開字節(jié)跳動小程序開發(fā)者工具,然后在項目編譯完后選擇項目根目錄下 dist 目錄進行預覽。

字節(jié)跳動小程序編譯預覽及打包(去掉 ?—watch? 將不會監(jiān)聽文件修改,并會對代碼進行壓縮打包)

  1. # yarn
  2. $ yarn dev:tt
  3. $ yarn build:tt
  4. # npm script
  5. $ npm run dev:tt
  6. $ npm run build:tt
  7. # 僅限全局安裝
  8. $ taro build --type tt --watch
  9. $ taro build --type tt
  10. # npx 用戶也可以使用
  11. $ npx taro build --type tt --watch
  12. $ npx taro build --type tt

QQ 小程序

選擇 QQ 小程序模式,需要自行下載并打開QQ 小程序開發(fā)者工具,然后在項目編譯完后選擇項目根目錄下 dist 目錄進行預覽。

QQ 小程序編譯預覽及打包(去掉? —watch? 將不會監(jiān)聽文件修改,并會對代碼進行壓縮打包)

  1. # yarn
  2. $ yarn dev:qq
  3. $ yarn build:qq
  4. # npm script
  5. $ npm run dev:qq
  6. $ npm run build:qq
  7. # 僅限全局安裝
  8. $ taro build --type qq --watch
  9. $ taro build --type qq
  10. # npx 用戶也可以使用
  11. $ npx taro build --type qq --watch
  12. $ npx taro build --type qq

常用 CLI 命令

查看 Taro 所有命令及幫助

  1. $ taro --help

環(huán)境及依賴檢測

Taro 提供了命令來一鍵檢測 Taro 環(huán)境及依賴的版本等信息,方便大家查看項目的環(huán)境及依賴,排查環(huán)境問題。在提問題的時候,請附上 ?taro info? 打印的信息,幫助開發(fā)人員快速定位問題。

  1. $ taro info
  2. ???? Taro v1.2.0-beta.15
  3. Taro CLI 1.2.0-beta.15 environment info:
  4. System:
  5. OS: macOS High Sierra 10.13.5
  6. Shell: 5.3 - /bin/zsh
  7. Binaries:
  8. Node: 8.11.2 - /usr/local/bin/node
  9. Yarn: 1.8.0 - /usr/local/bin/yarn
  10. npm: 5.6.0 - /usr/local/bin/npm
  11. npmPackages:
  12. @tarojs/components: ^1.2.0-beta.3 => 1.2.0-beta.3
  13. @tarojs/plugin-babel: ^1.2.0-beta.3 => 1.2.0-beta.3
  14. @tarojs/plugin-csso: ^1.2.0-beta.3 => 1.2.0-beta.3
  15. @tarojs/plugin-sass: ^1.2.0-beta.4 => 1.2.0-beta.4
  16. @tarojs/plugin-uglifyjs: ^1.2.0-beta.3 => 1.2.0-beta.3
  17. @tarojs/rn-runner: ^1.2.0-beta.4 => 1.2.0-beta.4
  18. @tarojs/router: ^1.2.0-beta.3 => 1.2.0-beta.3
  19. @tarojs/taro: ^1.2.0-beta.3 => 1.2.0-beta.3
  20. @tarojs/taro-alipay: ^1.2.0-beta.3 => 1.2.0-beta.3
  21. @tarojs/taro-h5: ^1.2.0-beta.3 => 1.2.0-beta.3
  22. @tarojs/taro-swan: ^1.2.0-beta.3 => 1.2.0-beta.3
  23. @tarojs/taro-weapp: ^1.2.0-beta.3 => 1.2.0-beta.3
  24. @tarojs/webpack-runner: ^1.2.0-beta.3 => 1.2.0-beta.3
  25. eslint-config-taro: ^1.2.0-beta.3 => 1.2.0-beta.3
  26. eslint-plugin-taro: ^1.2.0-beta.3 => 1.2.0-beta.3

Taro Doctor

Taro Doctor 就像一個醫(yī)生一樣,可以診斷項目的依賴、設置、結(jié)構(gòu),以及代碼的規(guī)范是否存在問題,并嘗試給出解決方案。

但和真正的醫(yī)生不一樣,Taro Doctor 不需要排隊掛號,也不用花錢。你只需要在終端運行命令:?taro doctor?,就像圖里一樣:

Taro Doctor 診斷結(jié)果圖

快速創(chuàng)建新頁面

?Taro create —name [頁面名稱]? 能夠在當前項目的pages目錄下快速生成新的頁面文件,并填充基礎代碼,是一個提高開發(fā)效率的利器。

CLI 配置

自 ?1.3.9? 開始支持

?1.3.9 ?開始 Taro 會在用戶根目錄下創(chuàng)建 .taro 文件夾,其中? .taro/index.json ?用于存放 CLI 相關(guān)配置。

開發(fā)者可以使用 ?taro config? 命令對配置項進行一系列操作:

  1. # 查看用法
  2. $ taro config --help
  3. # 設置配置項<key>的值為<value>
  4. $ taro config set <key> <value>
  5. # 讀取配置項<key>
  6. $ taro config get <key>
  7. # 刪除配置項<key>
  8. $ taro config delete <key>
  9. # 打印所有配置項
  10. $ taro config list [--json]

其他常見問題

回到某個版本

需要安裝某個固定版本,或者回到某個版本,例如我們要安裝 ?1.3.9? , 則如下:

  1. # 使用 npm 安裝 CLI
  2. $ npm install -g @tarojs/cli@1.3.9
  3. # OR 使用 yarn 安裝 CLI
  4. $ yarn global add @tarojs/cli@1.3.9
  5. # OR 安裝了 cnpm,使用 cnpm 安裝 CLI
  6. $ cnpm install -g @tarojs/cli@1.3.9

保持 @tarojs/cli 的版本與各端依賴版本一致

在使用 Taro 進行多端開發(fā)中,請保持 Taro CLI 的版本與你項目的依賴版本一致,否則可能會出現(xiàn)編譯錯誤或者運行時錯誤。

如果你所使用的 Taro CLI 版本為 1.3.9,而項目里使用的依賴版本為 1.3.20,則有可能會出現(xiàn)問題,這時請將你的 Taro CLI 版本更新至項目依賴版本號相同的版本,如果還是出現(xiàn)問題,請向我們提出問題。


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號