try adding update button again
This commit is contained in:
parent
b7096d8646
commit
98d64800fc
@ -2,6 +2,12 @@
|
||||
|
||||
import { register } from 'register-service-worker'
|
||||
|
||||
const notifyAboutUpdate = worker => {
|
||||
if (confirm('New version available, update?')) {
|
||||
worker.postMessage({ action : "skipWaiting"})
|
||||
}
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
register(`${process.env.BASE_URL}service-worker.js`, {
|
||||
ready () {
|
||||
@ -19,8 +25,9 @@ if (process.env.NODE_ENV === 'production') {
|
||||
updatefound () {
|
||||
console.log('New content is downloading.')
|
||||
},
|
||||
updated () {
|
||||
console.log('New content is available; please refresh.')
|
||||
updated (registration) {
|
||||
console.log('New content is available; please refresh.')
|
||||
notifyAboutUpdate(registration.waiting)
|
||||
},
|
||||
offline () {
|
||||
console.log('No internet connection found. App is running in offline mode.')
|
||||
@ -28,5 +35,12 @@ if (process.env.NODE_ENV === 'production') {
|
||||
error (error) {
|
||||
console.error('Error during service worker registration:', error)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
var refreshing;
|
||||
navigator.serviceWorker.addEventListener("controllerchange", function () {
|
||||
if (refreshing) return;
|
||||
window.location.reload();
|
||||
refreshing = true;
|
||||
})
|
||||
}
|
||||
|
9
frontend/src/service-worker.js
Normal file
9
frontend/src/service-worker.js
Normal file
@ -0,0 +1,9 @@
|
||||
self.__precacheManifest = [].concat(self.__precacheManifest || []);
|
||||
workbox.precaching.suppressWarnings()
|
||||
workbox.precaching.precacheAndRoute(self.__precacheManifest, {})
|
||||
|
||||
self.addEventListener('message', msg => {
|
||||
if (msg.data.action == 'skipwaiting') {
|
||||
self.skipWaiting();
|
||||
}
|
||||
})
|
@ -1,5 +1,3 @@
|
||||
const { GenerateSW } = require("workbox-webpack-plugin");
|
||||
|
||||
module.exports = {
|
||||
publicPath: "./",
|
||||
pwa: {
|
||||
@ -10,16 +8,10 @@ module.exports = {
|
||||
},
|
||||
workboxPluginMode: 'InjectManifest',
|
||||
workboxOptions: {
|
||||
swSrc: 'src/registerServiceWorker.js'
|
||||
swSrc: 'src/service-worker.js'
|
||||
}
|
||||
},
|
||||
configureWebpack: {
|
||||
plugins: [new GenerateSW({
|
||||
clientsClaim: true,
|
||||
skipWaiting: true,
|
||||
cleanupOutdatedCaches: true,
|
||||
navigateFallback: 'index.html',
|
||||
})],
|
||||
output: {
|
||||
crossOriginLoading: 'anonymous'
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user