registerServiceWorker.ts 932 B

12345678910111213141516171819202122232425262728293031
  1. /* eslint-disable no-console */
  2. import { register } from 'register-service-worker';
  3. if (navigator.serviceWorker) {
  4. if (process.env.NODE_ENV === 'production') {
  5. register(`${process.env.BASE_URL}service-worker.js`, {
  6. ready() {
  7. console.log('Production - App is being served from cache by a service worker.');
  8. },
  9. registered() {
  10. console.log('Production - Service worker has been registered.');
  11. },
  12. cached() {
  13. console.log('Production - Content has been cached for offline use.');
  14. },
  15. updatefound() {
  16. console.log('Production - New content is downloading.');
  17. },
  18. updated() {
  19. console.log('Production - New content is available; please refresh.');
  20. },
  21. offline() {
  22. console.log('Production - No internet connection found. App is running in offline mode.');
  23. },
  24. error(error: any) {
  25. console.log('Production - Error during service worker registration:' + error);
  26. },
  27. });
  28. }
  29. }