开发环境搭建
taro-cli
系统:macOS 10.14.2,nvm 0.33,node 版本 v8.12.0 LTS。
安装 taro-cli
npm install -g @tarojs/cli
使用 taro-cli 初始化 taro 项目
注意:$后面的是需要写的,taro-template是项目名(本行写到这即可)
[fengyfei-2:labs a1$ taro init taro-template👽 Taro v1.2.14Taro即将创建一个新项目!Need help? Go and open issue: https://github.com/NervJS/taro/issues/new? 请输入项目介绍! Template with Taro UI? 是否需要使用 TypeScript ? No? 请选择 CSS 预处理器(Sass/Less/Stylus) Sass? 请选择模板 Redux 模板✔ 创建项目: taro-template✔ 创建配置目录: taro-template/config✔ 创建源码目录: taro-template/src✔ 创建页面目录: taro-template/src/pages✔ 创建 actions 目录: taro-template/src/actions✔ 创建 constants 目录: taro-template/src/constants✔ 创建 reducers 目录: taro-template/src/reducers✔ 创建 store 目录: taro-template/src/store✔ 创建页面 JS 文件: taro-template/src/pages/index/index.js✔ 创建 action counter JS 文件: taro-template/src/actions/counter.js✔ 创建 constant counter JS 文件: taro-template/src/constants/counter.js✔ 创建 reducer counter JS 文件: taro-template/src/reducers/counter.js✔ 创建 reducer 入口 JS 文件: taro-template/src/reducers/index.js✔ 创建 store JS 文件: taro-template/src/store/index.js✔ 创建页面 SCSS 文件: taro-template/src/pages/index/index.scss✔ 创建文件: taro-template/src/app.js✔ 创建文件: taro-template/src/app.scss✔ 创建文件: taro-template/src/index.html✔ 创建文件: taro-template/config/index.js✔ 创建文件: taro-template/config/dev.js✔ 创建文件: taro-template/config/prod.js✔ 创建文件: taro-template/.editorconfig✔ 创建文件: taro-template/.gitignore✔ 创建文件: taro-template/package.json✔ 创建文件: taro-template/.eslintrc✔ 创建文件: taro-template/project.config.json✔ Initialized empty Git repository in /Users/fengyfei/Github/Go/src/github.com/fengyfei/labs/taro-template/.git/✔ 安装成功warning kleur@2.0.2: Please upgrade to kleur@3 or migrate to 'ansi-colors' if you prefer the old syntax. Visit <https://github.com/lukeed/kleur/releases/tag/v3.0.0\> for migration path(s).warning circular-json@0.3.3: CircularJSON is in maintenance only, flatted is its successor.yarn install v1.1.0info No lockfile found.[1/4] Resolving packages...[2/4] Fetching packages...[3/4] Linking dependencies...[4/4] Building fresh packages...success Saved lockfile.Done in 171.32s.创建项目 taro-template 成功!请进入项目目录 taro-template 开始工作吧!😝
taro-ui
进入创建的项目目录(一般taro-template创建在二级目录下,一级目录是本机带有的,这时候进入目录是 cd template/ 或者 cd ~/taro-template/。如果在三级目录,需要先找二级目录 比如 cd ~/github/,再找三级目录: cd ~template),执行:
npm i taro-ui -S
注意;如果本步失败,可能是少什么包,执行 npm i (把包全都装一遍),再次执行 npm i taro-ui -S
并在项目目录下 src/app.scss 导入全局配置文件
@import "~taro-ui/dist/style/index.scss";
运行小程序
在项目目录下执行如下命令
taro build --type weapp --watch
由于版本问题,可能会缺少依赖。缺少依赖需要安装
npm install @tarojs/plugin-csso --save-devtaro build --type weapp --watch
环境更改需要执行 npm rebuild npde-sass
This usually happens because your environment has changed since running `npm install`.Run `npm rebuild node-sass` to download the binding for your current environment.$ npm rebuild node-sass$ taro build --type weapp --watch
扩充
1s-MacBook-Air-5:samplate a1$ pwd/Users/a1/github/samplate1s-MacBook-Air-5:samplate a1$ cd ../1s-MacBook-Air-5:github a1$ ls -latotal 32drwxr-xr-x 23 a1 staff 736 3 25 14:42 .drwxr-xr-x+ 84 a1 staff 2688 3 23 17:53 ..-rw-r--r--@ 1 a1 staff 14340 3 24 11:28 .DS_Storedrwxr-xr-x 6 a1 staff 192 4 18 2018 .ideadrwxr-xr-x 3 a1 staff 96 11 28 2017 .vscodedrwxr-xr-x 43 a1 staff 1376 3 3 2018 GOdrwxr-xr-x 5 a1 staff 160 6 1 2018 community-data-statisticsdrwxr-xr-x 6 a1 staff 192 3 26 2018 gitTestdrwxr-xr-x 21 a1 staff 672 9 18 2018 gopackagedrwxr-xr-x 16 a1 staff 512 6 17 2018 gosnippetdrwxr-xr-x 3 a1 staff 96 4 18 2018 gostudydrwxr-xr-x 9 a1 staff 288 6 21 2018 graduation-projectdrwxr-xr-x 5 a1 staff 160 6 14 2018 issue-communitydrwxr-xr-x 7 a1 staff 224 11 12 15:51 javadrwxr-xr-x 44 a1 staff 1408 11 27 2017 js-studydrwxr-xr-x 9 a1 staff 288 11 17 2017 mini-appsdrwxr-xr-x 24 a1 staff 768 2 16 12:39 nvmdrwxr-xr-x 10 a1 staff 320 8 9 2018 picturedrwxr-xr-x 13 a1 staff 416 3 25 14:52 samplatedrwxr-xr-x 16 a1 staff 512 9 18 2018 shiruitao.github.iodrwxr-xr-x 15 a1 staff 480 3 22 19:47 taro-templatedrwxr-xr-x@ 11 a1 staff 352 8 9 2018 wxapp-malldrwxr-xr-x 14 a1 staff 448 3 12 18:46 yqlm1s-MacBook-Air-5:github a1$ ls -la samplate/total 48drwxr-xr-x 13 a1 staff 416 3 25 14:52 .drwxr-xr-x 23 a1 staff 736 3 25 14:42 ..-rw-r--r-- 1 a1 staff 197 3 25 14:42 .editorconfig-rw-r--r-- 1 a1 staff 221 3 25 14:42 .eslintrcdrwxr-xr-x 9 a1 staff 288 3 25 14:42 .git-rw-r--r-- 1 a1 staff 47 3 25 14:42 .gitignore-rw-r--r-- 1 a1 staff 166 3 25 14:42 .npmrcdrwxr-xr-x 5 a1 staff 160 3 25 14:42 configdrwxr-xr-x 4 a1 staff 128 3 25 14:54 distdrwxr-xr-x 1357 a1 staff 43424 3 25 14:52 node_modules-rw-r--r-- 1 a1 staff 2014 3 25 14:52 package.json-rw-r--r-- 1 a1 staff 271 3 25 14:53 project.config.jsondrwxr-xr-x 10 a1 staff 320 3 25 14:42 src1s-MacBook-Air-5:github a1$ cd samplate1s-MacBook-Air-5:samplate a1$ lsconfig dist node_modules package.json project.config.json src1s-MacBook-Air-5:samplate a1$ ls -latotal 48drwxr-xr-x 13 a1 staff 416 3 25 14:52 .drwxr-xr-x 23 a1 staff 736 3 25 14:42 ..-rw-r--r-- 1 a1 staff 197 3 25 14:42 .editorconfig-rw-r--r-- 1 a1 staff 221 3 25 14:42 .eslintrcdrwxr-xr-x 9 a1 staff 288 3 25 14:42 .git-rw-r--r-- 1 a1 staff 47 3 25 14:42 .gitignore-rw-r--r-- 1 a1 staff 166 3 25 14:42 .npmrcdrwxr-xr-x 5 a1 staff 160 3 25 14:42 configdrwxr-xr-x 4 a1 staff 128 3 25 14:54 distdrwxr-xr-x 1357 a1 staff 43424 3 25 14:52 node_modules-rw-r--r-- 1 a1 staff 2014 3 25 14:52 package.json-rw-r--r-- 1 a1 staff 271 3 25 14:53 project.config.jsondrwxr-xr-x 10 a1 staff 320 3 25 14:42 src1s-MacBook-Air-5:samplate a1$ rm -rf *1s-MacBook-Air-5:samplate a1$ ls -l1s-MacBook-Air-5:samplate a1$ ls -latotal 32drwxr-xr-x 7 a1 staff 224 3 25 15:01 .drwxr-xr-x 23 a1 staff 736 3 25 14:42 ..-rw-r--r-- 1 a1 staff 197 3 25 14:42 .editorconfig-rw-r--r-- 1 a1 staff 221 3 25 14:42 .eslintrcdrwxr-xr-x 9 a1 staff 288 3 25 14:42 .git-rw-r--r-- 1 a1 staff 47 3 25 14:42 .gitignore-rw-r--r-- 1 a1 staff 166 3 25 14:42 .npmrc1s-MacBook-Air-5:samplate a1$ rm -f .editorconfig .eslintrc .npmrc1s-MacBook-Air-5:samplate a1$ cd ../1s-MacBook-Air-5:github a1$ taro init samplate👽 Taro v1.2.21Taro即将创建一个新项目!Need help? Go and open issue: https://github.com/NervJS/taro/issues/new? 当前目录已经存在同名项目,请换一个项目名! 1s-MacBook-Air-5:github a1$1s-MacBook-Air-5:github a1$1s-MacBook-Air-5:github a1$1s-MacBook-Air-5:github a1$1s-MacBook-Air-5:github a1$ ls -latotal 32drwxr-xr-x 23 a1 staff 736 3 25 14:42 .drwxr-xr-x+ 84 a1 staff 2688 3 23 17:53 ..-rw-r--r--@ 1 a1 staff 14340 3 24 11:28 .DS_Storedrwxr-xr-x 6 a1 staff 192 4 18 2018 .ideadrwxr-xr-x 3 a1 staff 96 11 28 2017 .vscodedrwxr-xr-x 43 a1 staff 1376 3 3 2018 GOdrwxr-xr-x 5 a1 staff 160 6 1 2018 community-data-statisticsdrwxr-xr-x 6 a1 staff 192 3 26 2018 gitTestdrwxr-xr-x 21 a1 staff 672 9 18 2018 gopackagedrwxr-xr-x 16 a1 staff 512 6 17 2018 gosnippetdrwxr-xr-x 3 a1 staff 96 4 18 2018 gostudydrwxr-xr-x 9 a1 staff 288 6 21 2018 graduation-projectdrwxr-xr-x 5 a1 staff 160 6 14 2018 issue-communitydrwxr-xr-x 7 a1 staff 224 11 12 15:51 javadrwxr-xr-x 44 a1 staff 1408 11 27 2017 js-studydrwxr-xr-x 9 a1 staff 288 11 17 2017 mini-appsdrwxr-xr-x 24 a1 staff 768 2 16 12:39 nvmdrwxr-xr-x 10 a1 staff 320 8 9 2018 picturedrwxr-xr-x 4 a1 staff 128 3 25 15:01 samplatedrwxr-xr-x 16 a1 staff 512 9 18 2018 shiruitao.github.iodrwxr-xr-x 15 a1 staff 480 3 22 19:47 taro-templatedrwxr-xr-x@ 11 a1 staff 352 8 9 2018 wxapp-malldrwxr-xr-x 14 a1 staff 448 3 12 18:46 yqlm1s-MacBook-Air-5:github a1$ rm -rf samplate1s-MacBook-Air-5:github a1$1s-MacBook-Air-5:github a1$1s-MacBook-Air-5:github a1$1s-MacBook-Air-5:github a1$ sudo npm i taro-ui -SPassword:Sorry, try again.Password:sudo: 1 incorrect password attempt1s-MacBook-Air-5:github a1$ sudo npm install -g @tarojs/cliPassword:1s-MacBook-Air-5:github a1$ npm install -g @tarojs/cli
npm -vnode -vvi /Users/a1/.npm/_logs/2019-03-25T12_19_59_370Z-debug.logls -la /Users/a1/github/samplate/node_modules/_@tarojs_async-await@1.2.21@@tarojs/async-await/node_modules/ls -la /Users/a1/github/samplate/node_modules/_@tarojs_async-await@1.2.21@@tarojs/async-await/node_modulels -la /Users/a1/github/samplate/node_modules/_@tarojs_async-await@1.2.21@@tarojs/async-await/node_modulesls -la /Users/a1/github/samplate/node_modules/_@tarojs_async-await@1.2.21@@tarojs/async-await/node_modulesnpm icat package.json:qlscat project.config.jsonls -la config/ls -la config/index.jscat config/index.jscat ~/.npmrchistory | grep npmcnpm isudo rm -rf node_modulescnpm i
make: *** [Release/obj.target/fse/fsevents.o] Error 1gyp ERR! build errorgyp ERR! stack Error: `make` failed with exit code: 2gyp ERR! stack at ChildProcess.onExit (/Users/a1/.nvm/versions/node/v10.15.3/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:262:23)gyp ERR! stack at ChildProcess.emit (events.js:189:13)gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12)gyp ERR! System Darwin 17.7.0gyp ERR! command "/Users/a1/.nvm/versions/node/v10.15.3/bin/node" "/Users/a1/.nvm/versions/node/v10.15.3/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "build" "--fallback-to-build" "--module=/Users/a1/github/Libplate/node_modules/fsevents/lib/binding/Release/node-v64-darwin-x64/fse.node" "--module_name=fse" "--module_path=/Users/a1/github/Libplate/node_modules/fsevents/lib/binding/Release/node-v64-darwin-x64" "--napi_version=3" "--node_abi_napi=napi"gyp ERR! cwd /Users/a1/github/Libplate/node_modules/fseventsgyp ERR! node -v v10.15.3gyp ERR! node-gyp -v v3.8.0gyp ERR! not oknode-pre-gyp ERR! build errornode-pre-gyp ERR! stack Error: Failed to execute '/Users/a1/.nvm/versions/node/v10.15.3/bin/node /Users/a1/.nvm/versions/node/v10.15.3/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/Users/a1/github/Libplate/node_modules/fsevents/lib/binding/Release/node-v64-darwin-x64/fse.node --module_name=fse --module_path=/Users/a1/github/Libplate/node_modules/fsevents/lib/binding/Release/node-v64-darwin-x64 --napi_version=3 --node_abi_napi=napi' (1)node-pre-gyp ERR! stack at ChildProcess.<anonymous> (/Users/a1/github/Libplate/node_modules/fsevents/node_modules/node-pre-gyp/lib/util/compile.js:83:29)node-pre-gyp ERR! stack at ChildProcess.emit (events.js:189:13)node-pre-gyp ERR! stack at maybeClose (internal/child_process.js:970:16)node-pre-gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)node-pre-gyp ERR! System Darwin 17.7.0node-pre-gyp ERR! command "/Users/a1/.nvm/versions/node/v10.15.3/bin/node" "/Users/a1/github/Libplate/node_modules/fsevents/node_modules/node-pre-gyp/bin/node-pre-gyp" "install" "--fallback-to-build"node-pre-gyp ERR! cwd /Users/a1/github/Libplate/node_modules/fseventsnode-pre-gyp ERR! node -v v10.15.3node-pre-gyp ERR! node-pre-gyp -v v0.10.3node-pre-gyp ERR! not ok
