import 'core-js/stable' ; import 'regenerator-runtime/runtime' ; import { precacheAndRoute } from 'workbox-precaching' ; import { registerRoute , setDefaultHandler } from 'workbox-routing' ; import { ExpirationPlugin } from 'workbox-expiration' ; import { NetworkFirst , NetworkOnly , CacheFirst , } from 'workbox-strategies' ; const serviceWorker = self ; try { serviceWorker . onerror = ( er ) => { serviceWorker . pwa_sw__error = er ; } ; serviceWorker . addEventListener ( 'error' , ( err ) => { serviceWorker . pwa_sw__error = err ; } ) ; precacheAndRoute ( self . __WB_MANIFEST ) ; serviceWorker . addEventListener ( 'install' , ( ) => { serviceWorker . skipWaiting ( ) ; } ) ; serviceWorker . addEventListener ( 'activate' , ( ) => { serviceWorker . clients . claim ( ) ; } ) ; const getOfflineHtml = ( ) => { serviceWorker . paw__offline_assets = serviceWorker . paw__offline_assets || [ ] ; const scripts = serviceWorker . paw__offline_assets . filter ( ( a ) => a . endsWith ( '.js' ) ) . map ( ( js ) => `<script type="text/javascript" src="${ js }" async></script>` ) . join ( '' ) ; return `<!DOCTYPE html><html><head></head><body><div id="${ serviceWorker . paw__injected_variables . clientRootElementId }"></div>${ scripts }</body></html>` ; } ; registerRoute ( new RegExp ( `^${ serviceWorker . location . origin }/.*__hmm_update.*` ) , new NetworkOnly ( ) ) ; const assetsRegExp = /\.(css|js|jpg|png|jpeg|gif|woff|woff2|ttf|eot|ico|mp4|avi)$/ ; setDefaultHandler ( ( { event } ) => { const { request } = event ; const requestMethod = request . method . toUpperCase ( ) ; if ( requestMethod !== 'GET' ) { return fetch ( event . request ) ; } if ( request . url . indexOf ( serviceWorker . location . origin ) !== - 1 && assetsRegExp . test ( request . url ) ) { return new CacheFirst ( { cacheName : 'paw_cache' , plugins : [ new ExpirationPlugin ( { maxEntries : 50 , maxAgeSeconds : 30 * 24 * 60 * 60 , purgeOnQuotaError : true , } ) , ] , } ) . handle ( { event , request } ) . catch ( ( ex ) => { console . log ( ex ) ; } ) ; } if ( request . url . indexOf ( serviceWorker . location . origin ) === - 1 && assetsRegExp . test ( request . url ) ) { return new NetworkOnly ( ) . handle ( { event , request } ) . catch ( ( ex ) => { console . log ( ex ) ; } ) ; } if ( request . url . indexOf ( serviceWorker . location . origin ) !== - 1 && request . headers . get ( 'accept' ) . indexOf ( 'html' ) !== - 1 && request . mode === 'navigate' ) { return new NetworkFirst ( { cacheName : 'paw_cache' , plugins : [ new ExpirationPlugin ( { maxEntries : 50 , maxAgeSeconds : 30 * 24 * 60 * 60 , purgeOnQuotaError : true , } ) , ] , } ) . handle ( { event , request } ) . then ( ( response ) => { if ( ! response ) { return new Response ( getOfflineHtml ( ) , { headers : { 'Content-Type' : 'text/html' } } ) ; } return response ; } ) . catch ( ( ) => new Response ( getOfflineHtml ( ) , { headers : { 'Content-Type' : 'text/html' } } ) ) ; } return new NetworkFirst ( { cacheName : 'paw_cache' , plugins : [ new ExpirationPlugin ( { maxEntries : 50 , maxAgeSeconds : 30 * 24 * 60 * 60 , purgeOnQuotaError : true , } ) , ] , } ) . handle ( { event , request , } ) . catch ( ( e ) => console . log ( e ) ) ; } ) ; const resolve = ( obj ) => ( obj && obj . __esModule ? obj . default : obj ) ; const projectSW = resolve ( require ( 'pawProjectSW' ) ) ; if ( typeof projectSW === 'function' ) { projectSW ( ) ; } } catch ( ex ) { serviceWorker . pwa__error = ex ; }