Quickstarter for your first PWA site including a small hackish approach for your content to keep looking great.
1) Initial Commands
Creating an ionic app from a tab starter
ionic start TesTPWATabs tabs --v2
From project root, adding support for browser
ionic platform add browser
Running your PWA site
ionic run browser
Your site is contained in the /www folder. This is the folder you’ll need to deploy (Step 3)
2) Hackish approach - Setting max-width to 600 pixels when in browsers
In app.component.ts, in the constructor
isDesktop: boolean = false;
constructor(platform: Platform) {
//Check if running on desktop
if (platform.is('core')) {
// This will only print when on desktop
console.log("I'm in a desktop!");
this.isDesktop = true;
}
...
In app.html, adding conditional css
<ion-nav [ngClass]="{'ionic-container': isDesktop }" [root]="rootPage"></ion-nav>
In app.scss
ion-app, ion-nav, ion-tab, ion-tabs, .app-root {
right: 0; //.app-root by default is set to position:absolute; top:0; left:0;
margin: 0 auto; //in order to center the content
//Colour gradients for the sides
//fallback for old browsers
background: #4688FC;
//Chrome 10-25, Safari 5.1-6
background: -webkit-linear-gradient(#4688FC, #C7DAFF);
//W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari
background: linear-gradient(#4688FC, #C7DAFF);
}
//This class will only be used for desktops browsers
.ionic-container {
max-width: 600px;
}
3) Deploy your site
This is a great guide I have used to deploy on firebase:
If you have a link to a another guide to easily deploy on AWS, ionic cloud or any other hosting service, feel free to share it and I’ll insert it in the post.