ionic框架配置

发布时间:2020-07-25 19:56:07 作者:dingzhaoqiang
来源:网络 阅读:647

ionic简介

ionic是一个专注于用WEB开发技术,基于HTML5创建类似于手机平台原生应用的一个开发框架。目前绑定的与angularJS和SASS。这个框架的目的是从web的角度开发手机应用,基于PhoneGap的编译平台,可以实现编译成各个平台的应用程序。

ionic安装

首先需要安装cordova和android环境。这个参考:phoneGap之Android环境搭建,上面写的很详细,还有常见的错误及解决办法。
然后安装ionic:

npm install -g ionic

如果因为网络原因安装不上有两种办法:

1.修改npm源为淘宝npm源,可以使用下面三种方法中的任意一种

A.通过config命令

npm config set registry https://registry.npm.taobao.org 

npm info underscore (如果上面配置正确这个命令会有字符串response)

B.命令行指定

npm --registry https://registry.npm.taobao.org info underscore

C.编辑 ~/.npmrc 加入下面内容

registry = https://registry.npm.taobao.org

2.拷贝安装过的ionic目录,配置环境变量或者建立软连接。

安装完成之后,就可以使用ionic创建项目了。

ionic start myApp tabs   //创建带有top栏和bottom栏的示例项目

ionic start myApp sidemenu  //创建带有左侧带有menu栏的示例项目

ionic start myApp blank   //创建空白项目

具体效果,可以查看官网: http://ionicframework.com/getting-started/
然后可以使用:

ionic serve

该命令会自动启动流浏览器,查看当前效果。

添加Android平台

执行下面的命令,

cd myApp
ionic platform add android //这行可能会报错
ionic build android
ionic emulate android

其实上面的使用方法和cordova差不多,添加android的时候可能会报错,如下:

The error is: ======================================= events.js:72 throw er; // Unhandled 'error' event ^ Error: spawn ENOENT at errnoException (child_process.js:1000:11) at Process.ChildProcess._handle.onexit (child_process.js:791:34)

解决的方法很简单,将ionic换成cordova即可,经测试works fine。

cd myApp
cordova platform add android //这行可能会报错
cordova build android
cordova emulate android

其他常见错误

  1. 生成项目(ionic start myApp tabs)时可能会报错,如下:

Error: command failed:fatal:could not create work tree dir:'C:\Users/ADMINI~1\AppData\Local\Temp\plugman\git\1402853493773'.:No such file or directory

解决办法:进入上面对应的目录,建立对应的文件。比如在temp目录下建立plugman目录,在plugman目录下建立git目录,然后再git下建立1402853493773目录。即可,经测试有效。

2.sh: 1: node-gyp: Permission denied 安装软件包报错
这个一般是centos等系统,在root用户下安装会报错。主要是权限问题,报错详情:

> node-gyp rebuild

sh: 1: node-gyp: Permission denied
\
> ws@0.4.32 install /root/.nvm/versions/node/v0.12.4/lib/node_modules/log.io/node_modules/socket.io-client/node_modules/ws
> (node-gyp rebuild 2> builderror.log) || (exit 0)


> ws@0.4.32 install /root/.nvm/versions/node/v0.12.4/lib/node_modules/log.io/node_modules/socket.io/node_modules/socket.io-client/node_modules/ws
> (node-gyp rebuild 2> builderror.log) || (exit 0)

npm ERR! Linux 3.13.0-48-generic
npm ERR! argv "/root/.nvm/versions/node/v0.12.4/bin/node" "/root/.nvm/versions/node/v0.12.4/bin/npm" "install" "-g" " log.io"
npm ERR! node v0.12.4
npm ERR! npm v2.10.1
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn

npm ERR! contextify@0.1.14 install: `node-gyp rebuild`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the contextify@0.1.14 install script 'node-gyp rebuild'.
npm ERR! This is most likely a problem with the contextify package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-gyp rebuild
npm ERR! You can get their info via:
npm ERR! npm owner ls contextify
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! /root/npm-debug.log

可以清楚看到讯息中提示我们在执行node-gyp 的时候权限不足。

查询一下Google ,找到别人blog写得简单解决方法:

npm config set unsafe-perm true

接下来安装就正常了。 至于npm config的使用方法, 请参考 此处 .
我们可以从npm config set unsafe-perm的解说中看到,我们刚刚修改的意思。

Default: false if running as root, true otherwise
Type: Boolean
Set to true to suppress the UID/GID switching when running package scripts. If set explicitly to false, then installing as a non-root user will fail.


推荐阅读:
  1. ionic学习【1 环境配置搭建】
  2. ionic学习之建立一个ionic项目

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

ionic

上一篇:nagios服务搭建及常见报错处理

下一篇:nagios 客户端一键安装

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》