In this post, we'll introduce Ionic 4, learn about its new features and finally show you how to install and use the Ionic CLI v4 to generate a new Ionic project based on Angular 7.
We'll also introduce the new Ionic 4 ecosystem comprised of new tools like Stencil , Capacitor and modern browser technologies such as web components, shadow DOM and CSS variables.
Ionic 4 is the latest version of Ionic and the best Ionic yet! It's a mobile UI library that embraces modern browser technologies but also the new Angular 7 tooling and features.
While Ionic is now framework-agnostic, Ionic developers that still want to use Ionic with Angular will get support from the Ionic team with the
ionic/angular package, just like Ionic 3 and the previous versions.
Now, let's introduce the technologies behind the new Ionic.
Stencil is an open-source tool created by the Ionic team to help them easily build the Ionic Core with standard compliant web components.
Stencil is a web components compiler which allows you to use framework-like constructs such as JSX templates , routing , data binding and TypeScript classes and decorators to easily build web components — but your final application is completely based on web components that run natively on modern browsers.
The new Ionic uses Stencil behind the curtain — which means you don't need to use it when developing Ionic apps but you can use Stencil to author web components or create full Progressive Web Apps with or without the Ionic UI components.
Web components are a series of standards defined by the W3C. They allow front-end developers to build components that are natively interpreted by modern web browsers.
Among the technologies related to web components are Custom Elements and Shadow DOM .
Thanks to Custom Elements, we can re-use Ionic UI components in modern web browsers natively without any frameworks or run-times.
Shadow DOM is another native browser API that allows the encapsulation of DOM elements and CSS styles independently from the other code in an HTML document. It provides a way to attach a hidden DOM (called shadow root ) to an element using the
Using Shadow DOM helps to easily consume Ionic UI components from any web application by encapsulating the CSS styles.
Ionic Native provides a TypeScript wrapper for Cordova plugins for easily adding native device (Android and iOS) functionalities into your Ionic mobile application. It's basically a set of community maintained plugins.
Starting with version 5, Ionic Native is also framework independent. That means you can now use the wrappers outside of Angular. Check out the new Native API Docs .
You can migrate your existing Ionic 3 application to Ionic/Angular v4 by following the migration guide and use this official migration tool by Ionic which automatically detects most of the breaking changes and automatically fixes some issues.
The Ionic Command Line Utility or CLI is the official and primary tool — provided by the Ionic team — to create and build mobile apps based on Ionic and Cordova (or also Capacitor).
You can use the Ionic CLI to generate a project based on many starters. It is also used for:
The Ionic CLI v4 comes with new features, such as experimental support for Capacitor — a new alternative to Cordova built by the Ionic team to create cross-platform apps for mobile (Android and iOS), desktop (thanks to Electron ) and the web (as PWAs ).
To generate Ionic/Angular v4 projects, you need to install the Ionic CLI v4. Before installing the CLI, make sure you have the following requirements:
node --versionto check if Node.js is installed. If not, simply head to the official website and grab the binaries for your system.
Now, you can install the Ionic CLI globally from npm using the following command:
npm install -g ionic
Depending on your npm configuration, you may need to use
sudo on Linux/Mac or use an Administrator command prompt on Windows if you want to install packages globally.
After installing the Ionic CLI v4, you can create a new Ionic project using the
ionic start command and specifying the name and a starter template such as:
You also need to specify the type of framework to use with the
--type=angular option, which is new in the Ionic CLI v4 (for now, the CLI supports only Angular).
Head over to your terminal and run the following command:
ionic start myApp blank --type=angular
The CLI will ask you if you want to integrate Cordova. Answer Yes if you want to target native iOS and Android or No if you just want to create a Progressive Web App with Ionic.
This is a screenshot of the directory structure:
Most work you'll do will be inside the
src/app/ folder, which contains the root app component and module and any other directories for pages and components.
You can run and debug your Ionic application right in the browser using the
ionic serve command. This is one of the benefits of hybrid mobile development — you don't need to use emulators or actual mobile devices until you need to test native device features (presuming you can't mock the feature in the browser).
Head back to your terminal, navigate inside your project and serve your application using:
cd myApp ionic serve
Your application will be available from
In this post, we introduced the new Ionic 4 library and its new ecosystem, which comprises the tools and technologies behind the new powerful features. We also installed the Ionic CLI v4, created and served a new project based on Angular. Similarly, you should now be able to create a new Ionic 4 app and use the Ionic CLI v4.
If you're building Ionic applications with sensitive logic, be sure to protect them against code theft, tampering, and reverse-engineering by followingour guide .