Migration to injectManifest

This commit is contained in:
Matteo Gheza 2020-10-11 00:33:42 +02:00
parent 221228b797
commit d8e3655113
9 changed files with 89 additions and 17 deletions

View File

@ -0,0 +1,20 @@
{
"name": "Allerta",
"short_name": "Allerta VVF",
"icons": [
{
"src": "/resources/images/android-chrome-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "/resources/images/android-chrome-384x384.png",
"sizes": "384x384",
"type": "image/png"
}
],
"theme_color": "#ffffff",
"background_color": "#ffffff",
"start_url": "http://localhost:8080/",
"display": "standalone"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

View File

@ -0,0 +1,20 @@
{
"name": "",
"short_name": "",
"icons": [
{
"src": "/android-chrome-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "/android-chrome-384x384.png",
"sizes": "384x384",
"type": "image/png"
}
],
"theme_color": "#ffffff",
"background_color": "#ffffff",
"start_url": "http://localhost:8080/",
"display": "standalone"
}

View File

@ -52,10 +52,11 @@ $( document ).ready(function() {
});
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('/resources/dist/sw.js').then(registration => {
console.log('SW registered: ', registration);
}).catch(registrationError => {
console.log('SW registration failed: ', registrationError);
});
navigator.serviceWorker.register('/resources/dist/sw.js').then(registration => {
console.log('SW registered: ', registration);
//registration.pushManager.subscribe({userVisibleOnly: true});
}).catch(registrationError => {
console.log('SW registration failed: ', registrationError);
});
});
}
}

View File

@ -0,0 +1,30 @@
//import { CacheableResponsePlugin } from 'workbox-cacheable-response/CacheableResponsePlugin';
import { CacheFirst } from 'workbox-strategies/CacheFirst';
import { NetworkFirst } from 'workbox-strategies/NetworkFirst';
//import { ExpirationPlugin } from 'workbox-expiration/ExpirationPlugin';
//import { NavigationRoute } from 'workbox-routing/NavigationRoute';
import { precacheAndRoute } from 'workbox-precaching/precacheAndRoute';
import { registerRoute } from 'workbox-routing/registerRoute';
precacheAndRoute(self.__WB_MANIFEST);
registerRoute(
new RegExp('.*\.js'),
new NetworkFirst({
cacheName: 'js-cache',
})
);
registerRoute(
new RegExp('\.{svg,jpg,png,gif,ico}$'),
new CacheFirst({
cacheName: 'images-cache',
})
);
registerRoute(
new RegExp('\.{eot,ttf,woff,woff2}$'),
new CacheFirst({
cacheName: 'fonts-cache',
})
);

View File

@ -67,10 +67,18 @@ module.exports = {
$: 'jquery',
popper: 'popper.js'
}),
new workboxPlugin.GenerateSW({
new workboxPlugin.InjectManifest({
swSrc: './src/sw.js',
swDest: 'sw.js',
clientsClaim: true,
skipWaiting: true,
include: [
/\.html$/,
/\.js$/,
/\.css$/,
/\.woff2$/,
/\.jpg$/,
/\.png$/
],
maximumFileSizeToCacheInBytes: 100 * 1024 * 1024
})
],
optimization: {

View File

@ -1,8 +0,0 @@
module.exports = {
"globDirectory": ".",
"globPatterns": [
"**/*.{eot,svg,ttf,woff,woff2,png,js,gif,ico,mp3}"
],
"swDest": "sw.js",
"swSrc": ""
};

View File

@ -5,6 +5,7 @@
<title>{{ title }} - ALLERTA sistema gestionale {{ owner }}</title>
<link href="{{ urlsoftware }}/resources/images/favicon.ico" rel="shortcut icon" type="image/vnd.microsoft.icon">
<meta name="viewport" content="user-scalable=no, initial-scale=1">
<link rel="manifest" href="/manifest.webmanifest">
<style>
body:not(table){
max-width: 100%;