I have been doing some experiments with Ubports app development using Ionic framework and Angular. Being a web developer, I found it as the easiest way to start developing Ubports app. Here I am listing down the procedure I followed to make the app running in Ubports.
Since Ubports does not have official support from Cordova, I had to choose Ubports HTML app template which is just like running index.html from file system. These kind of apps do not have access to any API to use storage/location/contacts etc.
Changes I did to make Ionic app run from file system without server.
- Remove <base href="/" /> from index.html
- Add APP_BASE_HREF and LocationStrategy to app.module.ts file as follows
import { APP_BASE_HREF, LocationStrategy, HashLocationStrategy } from '@angular/common';
providers: [
StatusBar,
SplashScreen,
{ provide: APP_BASE_HREF, useValue: '/' },
{ provide: LocationStrategy, useClass: HashLocationStrategy },
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
],
Somehow the ionic prod build did not work for me. I had to choose normal ionic build using ionic build
In fact, ionic prod build is working fine now.
After build, all instance of type="module" should be deleted from index.html file of www folder.
With these changes, after build Ionic app can be run from file system without any server running. index.html file of www folder can be opened using chrome.
Another issue I faced when running app without server was with loading icons. Ionic keep each icons as separate svg files and load them when required. Unfortunately this does not work when running without server. I could successfully use fontawsome as described in angular-fontawesome github page. But I decided to use ionic components as much possible. So I created constants which hold full svg file content for the required icons and used instead of specifying just icon names as follows
closeIcon: 'data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" class="ionicon" viewBox="0 0 512 512"><path d="M289.94 256l95-95A24 24 0 00351 127l-95 95-95-95a24 24 0 00-34 34l95 95-95 95a24 24 0 1034 34l95-95 95 95a24 24 0 0034-34z"/></svg>'
template:
<ion-icon slot="icon-only" [src]="closeIcon"></ion-icon>
The app I created can be used as a template if you wish to develop app using ionic framework and angular. All files are uploaded to following github url
https://github.com/jittopjose/DoToDo
Just clone the project and run build-app.sh is enough to generate a click package (Provided clickable and ionic cli installed already). Thanks to Brian Douglass for the instructions given in his RecipeBoss gitlab page.
The performance is not as par with the performance of same app in android. I guess its because of the lack of hardware acceleration in ubports. Hopefully it will be fixed in the future.
I hope, ionic team or cordova team will support Ubport in the future and it will be a great help for people who are interested in creating hybrid app for Ubports.