Angular: Possible to use PWA on development server (ng serve)?

Issue

I’m working on an application where I’m using PWA for the first time and I’m trying to work with push notifications etc.

Currently I have PWA working if I execute the following commands ng build --prod and http-server -p 8080 -c-1 dist/myProject, but I was wondering if there was a way to have PWA work on ng serve so that I don’t constantly have to build the project because that takes quite some time.

EDIT: Added information

I tried modifying the serve object in angular.json by adding

            "assets": [
              "src/manifest.webmanifest"
            ]

to the options attribute but this gives the error Data path "" should NOT have additional properties(assets) so I suppose that this is not the way to go.

Solution

From the documentation:

Because ng serve does not work with service workers, you must use a separate HTTP server to test your project locally.

https://angular.io/guide/service-worker-getting-started#serving-with-http-server

Basically you can develop your app using the ng serve but you can’t install it or have updates when using ng serve. For that purposes you have to use the http-server

Answered By – Leonardo Alves

Answer Checked By – Pedro (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.