Follow me on Twitter or Dev.to:
This repository is the practical counterpart of my article Create Progressive Web Apps with Angular, Workbox, PWA Builder publisehd on Dev.to. The article is part of a series focusing on Progressive Web Apps technologies.
You can test the Angular PWA demo here.
The external APIs used:
First install or update your local project's npm dependencies:
npm install
Exceute a production build:
ng build --prod
This command will generate a dist/angular-pwa folder
As we cannot use ne serve
with service workers, you need to run a web server iof your choice. As example: http server or the web server Chrome extension and target the previously built dist/angular-pwa
folder.
Open the browser at the proposed address.
🔲 Make the application responsive
🔲 Show notification when a new SW version is available (use swUpdate)
🔲 Provide a dark mode
If, and only if, the service worker is not registered when the application is served locally via web server, then you can force explicitly the SW registration.
Add the following snipped in the main.ts
file:
platformBrowserDynamic()
.bootstrapModule(AppModule)
.then(() => {
if ('serviceWorker' in navigator && environment.production) {
navigator.serviceWorker.register('./ngsw-worker.js');
}
})
.catch(console.error);
Other users reported issues with some versions of the angular-cli: