Ionic:Hybrid Mobile App Development
上QQ阅读APP看书,第一时间看更新

Ionic development environment

Ionic Framework is based on Apache Cordova, which takes care of build and plugin management. Apache Cordova CLI uses the NodeJS package manager called NPM for dependency management.

Installing NodeJS

NodeJS is a JavaScript-based server-side environment to build backend systems. NodeJS has an efficient package manager that takes care of installing and maintaining a central repository of packages, version management, and dependency management. NPM has become the default dependency manager for a lot of other frameworks apart from NodeJS. Ionic Framework also leveraged this successful package manager so we have to install it for Hybrid App development.

In order to install NodeJS, download the binary for the respective OS—Windows, Linux, or Mac OS from https://nodejs.org/download/.

On a Mac or Linux, you can use a package manager such as brew to install NodeJS:

$ brew install node

After the node installation is complete, please type in the following commands to test the installation:

$ node -v
$ npm -v

The appropriate installed version for node and npm will be written to the output.

There is a config.json file generated that stores the dependent modules and meta information about the specific NodeJS project.

Basic npm commands

In order to install any npm package, the install command is used. It has an optional flag -g for installing any package globally so that it is accessible from anywhere. All the CLI packages such as Cordova CLI and Ionic CLI will be installed using these commands only. In order to update a package, run the second command:

$ npm install -g <package_name>
$ npm update -g <package_name>

Installing Cordova CLI and Ionic CLI

Cordova will be installed using the npm utility discussed previously. The Cordova CLI includes a set of scripts to automate the Cordova build process for wrapping of web content into Native Mobile Apps. It also includes commands to manage plugins. As discussed in Chapter 1, All About Hybrid Mobile Apps and Ionic Framework, Cordova is based on an architecture where the core library is included by default, but extra functionality needs to be utilized using plugins.

Installation command for Cordova CLI

In order to install Cordova, use the npm global install command as follows:

  • On a Mac/Linux machine: $ npm install -g cordova
  • On a Windows machine: C:\>npm install -g cordova

Cordova installation can be confirmed by checking the version of the installed package as follows:

$ cordova -v

The Ionic command-line interface provides an easy-to-use interface to perform basic functions such as creating an app, adding a platform, and building apps. It also provides commands to use Ionic platform services helping in rapid development of Hybrid Apps. Ionic CLI is installed in a method similar to Cordova with the following commands:

  • On a Mac/Linux machine: $ npm install -g ionic
  • On a Windows machine: C:\>npm install -g ionic

Ionic CLI extends the Cordova CLI and hence most of the Cordova commands need not be run directly. They can be run using the ionic keyword, where internally the Cordova package will be used. You can also view a list of exhaustive Ionic commands by executing ionic help.