Add minimal PWA (#34)
This commit is contained in:
4
src/ServiceWorker/sw.js
Normal file
4
src/ServiceWorker/sw.js
Normal file
@ -0,0 +1,4 @@
|
||||
/* eslint-disable no-console */
|
||||
|
||||
console.log('Hello from the service worker');
|
||||
|
@ -87,6 +87,9 @@ Vue.component('icon', FontAwesomeIcon)
|
||||
import VTooltip from 'v-tooltip'
|
||||
Vue.use(VTooltip)
|
||||
|
||||
// PWA
|
||||
import './registerServiceWorker'
|
||||
|
||||
// Set focus
|
||||
Vue.directive('focus', {
|
||||
// When the bound element is inserted into the DOM...
|
||||
|
31
src/registerServiceWorker.js
Normal file
31
src/registerServiceWorker.js
Normal file
@ -0,0 +1,31 @@
|
||||
/* eslint-disable no-console */
|
||||
|
||||
import { register } from 'register-service-worker'
|
||||
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
register(`${process.env.BASE_URL}sw.js`, {
|
||||
ready () {
|
||||
console.log(
|
||||
'App is being served from cache by a service worker.'
|
||||
)
|
||||
},
|
||||
registered () {
|
||||
console.log('Service worker has been registered.')
|
||||
},
|
||||
cached () {
|
||||
console.log('Content has been cached for offline use.')
|
||||
},
|
||||
updatefound () {
|
||||
console.log('New content is downloading.')
|
||||
},
|
||||
updated () {
|
||||
console.log('New content is available; please refresh.')
|
||||
},
|
||||
offline () {
|
||||
console.log('No internet connection found. App is running in offline mode.')
|
||||
},
|
||||
error (error) {
|
||||
console.error('Error during service worker registration:', error)
|
||||
}
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user