Tips: test PWA Angular apps locally


Difficulty

The Angular team has provided a quick command to implement the so-called PWA app.

ng add @angular/pwa --project *your-project-name*

Now, however, the classic ng serve command does not activate the potential of this type of app.
One way to activate service workers is to use an alternative local web server that simulates a real online web server.

A workaround could be to install a local http server like this:

npm install http-server --dev --save


Add it in scripts in package.json:

  "scripts": {
    "start:local": "ng build --prod && http-server -p 4200 -c-1 dist",
...


And run it with:

npm run start:local


Try it at home!

0
Be the first one to like this.
Please wait...

Leave a Reply

Thanks for choosing to leave a comment.
Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published.
Please do NOT use keywords in the name field. Let's have a personal and meaningful conversation.