Workbox

Installation

importScripts must run in the context of the service worker and not the main JavaScript thread. Consequently, if using webpack, do not import the service worker file Defined as an issue here and solving is from this issue

PWA

https://codelabs.developers.google.com/codelabs/workbox-lab

First thing is to generate a manifest file. A way to do it is to use workbox-cli

Workbox-cli does not work so I use this workbox-config.js:

module.exports = {
  globDirectory: "build/",
  globPatterns: [
    "**/*.css",
    "index.html",
    "js/animation.js",
    "images/home/*.jpg",
    "images/icon/*.svg"
  ],
  swSrc: "src/sw.js",
  swDest: "build/sw.js",
  globIgnores: ["../workbox-config.js"]
};