The Ionic CLI is your go-to tool for developing Ionic apps.
Ionic CLI is a great tool when it comes to avoid writing a lot of boilerlpate code. It generates pages, services, can run or emulate your Ionic application with and generate needed resources for the mobile application such as splash screen.
This is a quick reference into Ionic CLI.
Installing the CLI Tool
You can install it with npm:
To check if it has installed correctly, in your terminal window, type:
Starting a new App
To start with a new mobile application, Ionic framework provides different set of ready-to-use templates:
For creating a new project:
With update to Ionic 3, no more adding tages such as –v2 after the template name in the above command. By default, Ionic app generated will be of version 2/3. To generate an Ionic app of version 1 (with good ol’ Angularjs):
Once you cd into your project’s directory, serve your app on your local machine with serve:
To serve on a different port:
Use –-lab tag to see your app side by side on multiple platforms (such as iOS, Android and Windows Mobile):
To serve without live reload:
Generating Providers and Pages
To generate a new page:
To generate a provider/service:
Know them all- List the available generators:
To generate the app icon and splash screen with resources:
Or, just the splash screen:
Now, generate resources for a specific platform:
To add a target mobile platform for the app to use:
App on an Emulator
To start an emulator:
Emulate with livereload:
Running Ionic App on a Connected Device
Let’s say, I have an iOS device connected, so to run the app on that device:
Another advantage of using Ionic CLI tool is that it initialises a git repository when creating an Ionic project using the ionic start command from the terminal with an initial commit already. You can verify that by running:
You can also find me on Twitter
Gurupriyan is a Software Engineer and a technology enthusiast, he’s been working on the field for the last 6 years. Currently focusing on mobile app development and IoT.