@cocreate/pwa 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/{src → demo}/css/global.css +0 -0
- package/{src → demo}/css/style.css +1 -1
- package/{src → demo}/css/test1.css +0 -0
- package/{src → demo}/css/test2.css +0 -0
- package/{src → demo}/css/test3.css +0 -0
- package/{src → demo}/images/icons/icon-128x128.png +0 -0
- package/{src → demo}/images/icons/icon-144x144.png +0 -0
- package/{src → demo}/images/icons/icon-152x152.png +0 -0
- package/{src → demo}/images/icons/icon-192x192.png +0 -0
- package/{src → demo}/images/icons/icon-256x256.png +0 -0
- package/{src → demo}/images/icons/icon-384x384.png +0 -0
- package/{src → demo}/images/icons/icon-512x512.png +0 -0
- package/{src → demo}/images/icons/icon-72x72.png +0 -0
- package/{src → demo}/images/icons/icon-96x96.png +0 -0
- package/{src → demo}/images/no-img.jpg +0 -0
- package/{src/test2.html → demo/index.html} +16 -18
- package/{src → demo}/js/test1.js +0 -0
- package/{src → demo}/js/test2.js +0 -0
- package/{src → demo}/js/test3.js +0 -0
- package/{src → demo}/manifest.json +0 -0
- package/{src → demo}/offline.html +0 -0
- package/{src → demo}/pages/test1.html +2 -11
- package/{src → demo}/pages/test2.html +2 -9
- package/{src → demo}/pages/test3.html +3 -8
- package/demo/sw.js +99 -0
- package/package.json +10 -6
- package/src/cache.js +44 -0
- package/src/{js/app.js → index.js} +30 -36
- package/webpack.config.js +6 -7
- package/.vscode/settings.json +0 -2
- package/src/.jshintrc +0 -75
- package/src/archive/index.test.html +0 -41
- package/src/archive/script.js +0 -102
- package/src/archive/service-worker.js +0 -37
- package/src/archive/style.css +0 -35
- package/src/archive/sw-basico.js +0 -38
- package/src/archive/sw-estrategias.js +0 -190
- package/src/index.html +0 -102
- package/src/pages/offline.html +0 -29
- package/src/sw.js +0 -95
- package/src/test1.html +0 -62
- package/src/test3.html +0 -60
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [1.1.0](https://github.com/CoCreate-app/CoCreate-pwa/compare/v1.0.0...v1.1.0) (2022-09-16)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* dynamically cache files for offline support and keep them current when online ([0ff4e22](https://github.com/CoCreate-app/CoCreate-pwa/commit/0ff4e222a766c1f1c5bc78d61b18420bf46d6e32))
|
|
7
|
+
|
|
1
8
|
# 1.0.0 (2021-11-01)
|
|
2
9
|
|
|
3
10
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -8,29 +8,27 @@
|
|
|
8
8
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
9
9
|
<!-- import the webpage's stylesheet -->
|
|
10
10
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" />
|
|
11
|
-
<link rel="stylesheet" href="css/style.css" />
|
|
12
|
-
<link rel="stylesheet" href="css/test2.css" />
|
|
11
|
+
<link rel="stylesheet" href="./css/style.css" />
|
|
13
12
|
<!-- Manifest -->
|
|
14
|
-
<link rel="manifest" href="manifest.json" />
|
|
15
|
-
<!--<
|
|
13
|
+
<!-- <link rel="manifest" href="./manifest.json" /> -->
|
|
14
|
+
<!--<meta name="theme-color" content="red">-->
|
|
16
15
|
</head>
|
|
17
16
|
|
|
18
|
-
<body
|
|
19
|
-
<h1>InstallableR - TEST 2</h1>
|
|
17
|
+
<body>
|
|
20
18
|
<nav class="navbar navbar-expand-sm bg-dark">
|
|
21
19
|
<!-- Links -->
|
|
22
20
|
<ul class="navbar-nav">
|
|
23
21
|
<li class="nav-item active">
|
|
24
|
-
<a class="nav-link" href="
|
|
22
|
+
<a class="nav-link" href="#">Home</a>
|
|
25
23
|
</li>
|
|
26
24
|
<li class="nav-item">
|
|
27
|
-
<a class="nav-link" href="./test1.html">Test1</a>
|
|
25
|
+
<a class="nav-link" href="./pages/test1.html">Test1</a>
|
|
28
26
|
</li>
|
|
29
27
|
<li class="nav-item">
|
|
30
|
-
<a class="nav-link" href="
|
|
28
|
+
<a class="nav-link" href="./pages/test2.html">Test 2</a>
|
|
31
29
|
</li>
|
|
32
30
|
<li class="nav-item">
|
|
33
|
-
<a class="nav-link" href="./test3.html">Test 3</a>
|
|
31
|
+
<a class="nav-link" href="./pages/test3.html">Test 3</a>
|
|
34
32
|
</li>
|
|
35
33
|
</ul>
|
|
36
34
|
</nav>
|
|
@@ -40,21 +38,21 @@
|
|
|
40
38
|
</p>
|
|
41
39
|
|
|
42
40
|
<p>
|
|
43
|
-
Make me installable, follow the
|
|
41
|
+
To Make me installable, follow the
|
|
44
42
|
<a href="https://web.dev/codelab-make-installable/">instructions</a> here.
|
|
45
43
|
</p>
|
|
46
44
|
|
|
45
|
+
<button id="cacheBtn">Uncache</button>
|
|
46
|
+
|
|
47
47
|
<!-- Install button, hidden by default -->
|
|
48
48
|
<div id="installContainer" class="hidden">
|
|
49
|
-
<button id="
|
|
49
|
+
<button id="installBtn" type="button">Install</button>
|
|
50
50
|
</div>
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
<
|
|
55
|
-
|
|
56
|
-
<!-- import the webpage's javascript file -->
|
|
57
|
-
<script src="js/app.js" defer></script>
|
|
52
|
+
|
|
53
|
+
<!-- <script src="../src/index.js" defer></script> -->
|
|
54
|
+
<script src="../dist/CoCreate-pwa.js" defer></script>
|
|
55
|
+
|
|
58
56
|
</body>
|
|
59
57
|
|
|
60
58
|
</html>
|
package/{src → demo}/js/test1.js
RENAMED
|
File without changes
|
package/{src → demo}/js/test2.js
RENAMED
|
File without changes
|
package/{src → demo}/js/test3.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -9,15 +9,11 @@
|
|
|
9
9
|
<!-- import the webpage's stylesheet -->
|
|
10
10
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" />
|
|
11
11
|
<link rel="stylesheet" href="../css/style.css" />
|
|
12
|
-
<link rel="stylesheet" href="../css/test1.css" />
|
|
13
12
|
<!-- Manifest -->
|
|
14
13
|
<link rel="manifest" href="../manifest.json" />
|
|
15
|
-
<!--<link rel="manifest" href="./manifest.webmanifest"> -->
|
|
16
14
|
</head>
|
|
17
15
|
|
|
18
16
|
<body class="test1-bg-color">
|
|
19
|
-
|
|
20
|
-
<h1>InstallableR - TEST 1</h1>
|
|
21
17
|
<nav class="navbar navbar-expand-sm bg-dark">
|
|
22
18
|
<!-- Links -->
|
|
23
19
|
<ul class="navbar-nav">
|
|
@@ -48,15 +44,10 @@
|
|
|
48
44
|
|
|
49
45
|
<!-- Install button, hidden by default -->
|
|
50
46
|
<div id="installContainer" class="hidden">
|
|
51
|
-
<button id="
|
|
47
|
+
<button id="installBtn" type="button">Install</button>
|
|
52
48
|
</div>
|
|
53
49
|
|
|
54
|
-
|
|
55
|
-
to make it easier for folks to view source and remix -->
|
|
56
|
-
<div class="glitchButton" style="position:fixed;top:20px;right:20px;"></div>
|
|
57
|
-
<script src="https://button.glitch.me/button.js"></script>
|
|
58
|
-
<!-- import the webpage's javascript file -->
|
|
59
|
-
<script src="../js/app.js" defer></script>
|
|
50
|
+
<script src="../../dist/CoCreate-pwa.js" defer></script>
|
|
60
51
|
</body>
|
|
61
52
|
|
|
62
53
|
</html>
|
|
@@ -12,11 +12,9 @@
|
|
|
12
12
|
<link rel="stylesheet" href="../css/test2.css" />
|
|
13
13
|
<!-- Manifest -->
|
|
14
14
|
<link rel="manifest" href="../manifest.json" />
|
|
15
|
-
<!--<link rel="manifest" href="./manifest.webmanifest"> -->
|
|
16
15
|
</head>
|
|
17
16
|
|
|
18
17
|
<body class="test2-bg-color">
|
|
19
|
-
<h1>InstallableR - TEST 2</h1>
|
|
20
18
|
<nav class="navbar navbar-expand-sm bg-dark">
|
|
21
19
|
<!-- Links -->
|
|
22
20
|
<ul class="navbar-nav">
|
|
@@ -46,15 +44,10 @@
|
|
|
46
44
|
|
|
47
45
|
<!-- Install button, hidden by default -->
|
|
48
46
|
<div id="installContainer" class="hidden">
|
|
49
|
-
<button id="
|
|
47
|
+
<button id="installBtn" type="button">Install</button>
|
|
50
48
|
</div>
|
|
51
49
|
|
|
52
|
-
|
|
53
|
-
to make it easier for folks to view source and remix -->
|
|
54
|
-
<div class="glitchButton" style="position:fixed;top:20px;right:20px;"></div>
|
|
55
|
-
<script src="https://button.glitch.me/button.js"></script>
|
|
56
|
-
<!-- import the webpage's javascript file -->
|
|
57
|
-
<script src="../js/app.js" defer></script>
|
|
50
|
+
<script src="../../dist/CoCreate-pwa.js" defer></script>
|
|
58
51
|
</body>
|
|
59
52
|
|
|
60
53
|
</html>
|
|
@@ -16,7 +16,6 @@
|
|
|
16
16
|
</head>
|
|
17
17
|
|
|
18
18
|
<body class="test3-bg-color">
|
|
19
|
-
<h1>InstallableR - TEST 3</h1>
|
|
20
19
|
<nav class="navbar navbar-expand-sm bg-dark">
|
|
21
20
|
<!-- Links -->
|
|
22
21
|
<ul class="navbar-nav">
|
|
@@ -46,15 +45,11 @@
|
|
|
46
45
|
|
|
47
46
|
<!-- Install button, hidden by default -->
|
|
48
47
|
<div id="installContainer" class="hidden">
|
|
49
|
-
<button id="
|
|
48
|
+
<button id="installBtn" type="button">Install</button>
|
|
50
49
|
</div>
|
|
51
50
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
<div class="glitchButton" style="position:fixed;top:20px;right:20px;"></div>
|
|
55
|
-
<script src="https://button.glitch.me/button.js"></script>
|
|
56
|
-
<!-- import the webpage's javascript file -->
|
|
57
|
-
<script src="../js/app.js" defer></script>
|
|
51
|
+
<script src="../../dist/CoCreate-pwa.js" defer></script>
|
|
52
|
+
|
|
58
53
|
</body>
|
|
59
54
|
|
|
60
55
|
</html>
|
package/demo/sw.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
const CACHE_STATIC_NAME = "static-v1";
|
|
2
|
+
const CACHE_DYNAMIC_NAME = "dynamic-v2";
|
|
3
|
+
const CACHE_INMUTABLE_NAME = "inmutable-v1";
|
|
4
|
+
const CACHE_TEMP = 'temp-cache';
|
|
5
|
+
const CACHE_DYNAMIC_LIMIT = 50;
|
|
6
|
+
const fetchedMap = []
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
function deleteCache(key) {
|
|
10
|
+
return caches.delete(key);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
self.addEventListener("install", (e) => {
|
|
14
|
+
console.log('Service Worker Installing')
|
|
15
|
+
|
|
16
|
+
self.skipWaiting();
|
|
17
|
+
// caches.open(CACHE_DYNAMIC_NAME).then((cache) => {
|
|
18
|
+
// cache.keys().then((keys) => {
|
|
19
|
+
// keys.forEach(key => {
|
|
20
|
+
// fetchedMap.push(key.url)
|
|
21
|
+
// })
|
|
22
|
+
// deleteCache()
|
|
23
|
+
// })
|
|
24
|
+
// })
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
self.addEventListener("activate", async (e) => {
|
|
28
|
+
// console.log('sw activate Event!')
|
|
29
|
+
// const bgFetch = await self.registration.backgroundFetch.fetch(new Date().toISOString(), fetchedMap);
|
|
30
|
+
// console.log('backgfetch', bgFetch)
|
|
31
|
+
|
|
32
|
+
// e.waitUntil(updateCache())
|
|
33
|
+
// updateCache()
|
|
34
|
+
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
self.addEventListener("fetch", (e) => {
|
|
38
|
+
if (!(e.request.url.indexOf('http') === 0)) return;
|
|
39
|
+
e.respondWith(
|
|
40
|
+
caches
|
|
41
|
+
.match(e.request)
|
|
42
|
+
.then((cachesObj) => {
|
|
43
|
+
if (!navigator.onLine && !!cachesObj) {
|
|
44
|
+
return cachesObj;
|
|
45
|
+
}
|
|
46
|
+
return fetch(e.request)
|
|
47
|
+
.then((newResp) => {
|
|
48
|
+
caches
|
|
49
|
+
.open(CACHE_DYNAMIC_NAME)
|
|
50
|
+
.then((cache) => {
|
|
51
|
+
cache.put(e.request, newResp);
|
|
52
|
+
// cleanCache(CACHE_DYNAMIC_NAME, CACHE_DYNAMIC_LIMIT);
|
|
53
|
+
})
|
|
54
|
+
.catch(() => {});
|
|
55
|
+
return newResp.clone();
|
|
56
|
+
})
|
|
57
|
+
.catch(() => {
|
|
58
|
+
return caches.match('./offline.html');
|
|
59
|
+
})
|
|
60
|
+
})
|
|
61
|
+
.catch(function() {
|
|
62
|
+
console.log('Fetch failed retuned offline page! ')
|
|
63
|
+
return caches.match('./offline.html');
|
|
64
|
+
})
|
|
65
|
+
);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
async function updateCache(){
|
|
69
|
+
console.log('updateCache!')
|
|
70
|
+
caches.open(CACHE_DYNAMIC_NAME)
|
|
71
|
+
.then((cache) => {
|
|
72
|
+
console.log('added', fetchedMap)
|
|
73
|
+
cache.addAll(fetchedMap)
|
|
74
|
+
}
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
self.addEventListener('backgroundfetchsuccess', (event) => {
|
|
79
|
+
const bgFetch = event.registration;
|
|
80
|
+
|
|
81
|
+
event.waitUntil(async function() {
|
|
82
|
+
// Create/open a cache.
|
|
83
|
+
const cache = await caches.open(CACHE_DYNAMIC_NAME);
|
|
84
|
+
// Get all the records.
|
|
85
|
+
const records = await bgFetch.matchAll();
|
|
86
|
+
// Copy each request/response across.
|
|
87
|
+
const promises = records.map(async (record) => {
|
|
88
|
+
const response = await record.responseReady;
|
|
89
|
+
console.log('putting ')
|
|
90
|
+
await cache.put(record.request, response);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// Wait for the copying to complete
|
|
94
|
+
await Promise.all(promises);
|
|
95
|
+
|
|
96
|
+
// Update the progress notification.
|
|
97
|
+
// event.updateUI({ title: 'Episode 5 ready to listen!' });
|
|
98
|
+
}());
|
|
99
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/pwa",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "A simple pwa component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pwa",
|
|
@@ -40,14 +40,18 @@
|
|
|
40
40
|
},
|
|
41
41
|
"homepage": "https://cocreate.app/docs/pwa",
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@babel/core": "^7.
|
|
44
|
-
"@babel/preset-env": "^7.
|
|
45
|
-
"babel-loader": "^8.
|
|
43
|
+
"@babel/core": "^7.9.6",
|
|
44
|
+
"@babel/preset-env": "^7.9.6",
|
|
45
|
+
"babel-loader": "^8.1.0",
|
|
46
46
|
"clean-webpack-plugin": "^3.0.0",
|
|
47
|
+
"file-loader": "^6.2.0",
|
|
47
48
|
"html-webpack-plugin": "^4.5.0",
|
|
49
|
+
"mini-css-extract-plugin": "^1.5.0",
|
|
50
|
+
"style-loader": "^2.0.0",
|
|
51
|
+
"terser-webpack-plugin": "^5.1.1",
|
|
48
52
|
"uglifyjs-webpack-plugin": "^2.2.0",
|
|
49
|
-
"webpack": "^5.
|
|
50
|
-
"webpack-cli": "^4.
|
|
53
|
+
"webpack": "^5.24.4",
|
|
54
|
+
"webpack-cli": "^4.5.0",
|
|
51
55
|
"webpack-log": "^3.0.1"
|
|
52
56
|
},
|
|
53
57
|
"dependencies": {
|
package/src/cache.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const cacheBtn = document.getElementById('cacheBtn');
|
|
2
|
+
|
|
3
|
+
function deleteCache(cache) {
|
|
4
|
+
if ('serviceWorker' in navigator) {
|
|
5
|
+
return caches.delete(key);
|
|
6
|
+
|
|
7
|
+
// caches.keys().then(function(cacheNames) {
|
|
8
|
+
// cacheNames.forEach(function(cacheName) {
|
|
9
|
+
// if (cacheName == cache)
|
|
10
|
+
// caches.delete(cacheName);
|
|
11
|
+
// });
|
|
12
|
+
// });
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// function cleanCache(cacheName, numeroItems) {
|
|
17
|
+
// caches.open(cacheName).then((cache) => {
|
|
18
|
+
// return cache.keys().then((keys) => {
|
|
19
|
+
// if (keys.length > numeroItems) {
|
|
20
|
+
// cache.delete(keys[0]).then(cleanCache(cacheName, numeroItems));
|
|
21
|
+
// }
|
|
22
|
+
// });
|
|
23
|
+
// });
|
|
24
|
+
// }
|
|
25
|
+
|
|
26
|
+
function deleteFile(cacheName, fileName) {
|
|
27
|
+
if ('serviceWorker' in navigator) {
|
|
28
|
+
caches.open(cacheName).then(function(cache) {
|
|
29
|
+
cache.delete(fileName).then(function(response) {
|
|
30
|
+
return response
|
|
31
|
+
// console.log(cacheName, fileName, response)
|
|
32
|
+
});
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
if (cacheBtn) {
|
|
39
|
+
cacheBtn.addEventListener('click', function() {
|
|
40
|
+
deleteFile('dynamic-v2', '/CoCreate-components/CoCreate-pwa/src/index.js');
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export {deleteCache, deleteFile}
|
|
@@ -1,18 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
const butInstall = document.getElementById('butInstall');
|
|
3
|
-
const butCache = document.getElementById('butCache');
|
|
1
|
+
import cache from './cache.js'
|
|
4
2
|
|
|
5
|
-
/* Only register a service worker if it's supported */
|
|
6
|
-
// if ('serviceWorker' in navigator) {
|
|
7
|
-
// //navigator.serviceWorker.register('service-worker.js').then(console.log('success')).catch(console.log('fail'));
|
|
8
|
-
// window.addEventListener("load", function() {
|
|
9
|
-
// navigator.serviceWorker
|
|
10
|
-
// .register("sw.js")
|
|
11
|
-
// .then(res => console.log("service worker registered"))
|
|
12
|
-
// .catch(err => console.log("service worker not registered", err))
|
|
13
|
-
// })
|
|
14
|
-
// }
|
|
15
3
|
|
|
4
|
+
const installContainer = document.getElementById('installContainer');
|
|
5
|
+
const installBtn = document.getElementById('installBtn');
|
|
16
6
|
|
|
17
7
|
/**
|
|
18
8
|
* Warn the page must be served over HTTPS
|
|
@@ -32,11 +22,11 @@ window.addEventListener('beforeinstallprompt', (event) => {
|
|
|
32
22
|
// Stash the event so it can be triggered later.
|
|
33
23
|
window.deferredPrompt = event;
|
|
34
24
|
// Remove the 'hidden' class from the install button container
|
|
35
|
-
|
|
25
|
+
installContainer.classList.toggle('hidden', false);
|
|
36
26
|
});
|
|
37
27
|
|
|
38
|
-
|
|
39
|
-
console.log('👍', '
|
|
28
|
+
installBtn.addEventListener('click', async() => {
|
|
29
|
+
console.log('👍', 'installBtn-clicked');
|
|
40
30
|
const promptEvent = window.deferredPrompt;
|
|
41
31
|
if (!promptEvent) {
|
|
42
32
|
// The deferred prompt isn't available.
|
|
@@ -51,7 +41,7 @@ butInstall.addEventListener('click', async() => {
|
|
|
51
41
|
// prompt() can only be called once.
|
|
52
42
|
window.deferredPrompt = null;
|
|
53
43
|
// Hide the install button.
|
|
54
|
-
|
|
44
|
+
installContainer.classList.toggle('hidden', true);
|
|
55
45
|
});
|
|
56
46
|
|
|
57
47
|
window.addEventListener('appinstalled', (event) => {
|
|
@@ -60,27 +50,31 @@ window.addEventListener('appinstalled', (event) => {
|
|
|
60
50
|
window.deferredPrompt = null;
|
|
61
51
|
});
|
|
62
52
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
cache.delete(fileName).then(function(response) {
|
|
67
|
-
|
|
68
|
-
});
|
|
69
|
-
})
|
|
70
|
-
}
|
|
71
|
-
}
|
|
53
|
+
let workerPath = 'sw.js'
|
|
54
|
+
// if (config && config.serviceWorker)
|
|
55
|
+
// workerPath = config.serviceWorker
|
|
72
56
|
|
|
73
|
-
function
|
|
57
|
+
window.addEventListener("load", function(event) {
|
|
74
58
|
if ('serviceWorker' in navigator) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
59
|
+
navigator.serviceWorker.getRegistration(workerPath).then(registration => {
|
|
60
|
+
if(registration && registration.active) {
|
|
61
|
+
console.log('Service Worker Active')
|
|
62
|
+
} else {
|
|
63
|
+
navigator.serviceWorker.register(workerPath)
|
|
64
|
+
.then(reg => {
|
|
65
|
+
reg.onupdatefound = () => {
|
|
66
|
+
const installingWorker = reg.installing;
|
|
67
|
+
installingWorker.onstatechange = () => {
|
|
68
|
+
console.log('Service Worker', installingWorker.state);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
})
|
|
72
|
+
.catch(err => console.log('SW ERROR', err));
|
|
73
|
+
|
|
74
|
+
}
|
|
80
75
|
});
|
|
81
76
|
}
|
|
82
|
-
}
|
|
77
|
+
});
|
|
78
|
+
|
|
83
79
|
|
|
84
|
-
|
|
85
|
-
uncacheFileInCache('dynamic-v2', './src/css/style.css');
|
|
86
|
-
});
|
|
80
|
+
export default {cache}
|
package/webpack.config.js
CHANGED
|
@@ -3,15 +3,14 @@ const TerserPlugin = require("terser-webpack-plugin")
|
|
|
3
3
|
const MiniCssExtractPlugin = require("mini-css-extract-plugin")
|
|
4
4
|
let isProduction = process.env.NODE_ENV === "production"
|
|
5
5
|
const { CleanWebpackPlugin } = require("clean-webpack-plugin")
|
|
6
|
-
const HtmlWebpackPlugin = require("html-webpack-plugin")
|
|
7
6
|
|
|
8
7
|
module.exports = {
|
|
9
8
|
entry: {
|
|
10
|
-
"CoCreate-pwa": "./src/
|
|
9
|
+
"CoCreate-pwa": "./src/index.js",
|
|
11
10
|
},
|
|
12
11
|
output: {
|
|
13
12
|
path: path.resolve(__dirname, "dist"),
|
|
14
|
-
filename: isProduction ? "[name].min.js" : "[name]
|
|
13
|
+
filename: isProduction ? "[name].min.js" : "[name].js",
|
|
15
14
|
libraryTarget: "umd",
|
|
16
15
|
libraryExport: "default",
|
|
17
16
|
library: ["CoCreate", "pwa"],
|
|
@@ -24,10 +23,6 @@ module.exports = {
|
|
|
24
23
|
new MiniCssExtractPlugin({
|
|
25
24
|
filename: "[name].css",
|
|
26
25
|
}),
|
|
27
|
-
|
|
28
|
-
new HtmlWebpackPlugin({
|
|
29
|
-
template: "./src/index.html",
|
|
30
|
-
}),
|
|
31
26
|
],
|
|
32
27
|
// Default mode for Webpack is production.
|
|
33
28
|
// Depending on mode Webpack will apply different things
|
|
@@ -81,6 +76,10 @@ module.exports = {
|
|
|
81
76
|
minSize: 200,
|
|
82
77
|
// maxSize: 99999,
|
|
83
78
|
//minChunks: 1,
|
|
79
|
+
|
|
80
|
+
cacheGroups: {
|
|
81
|
+
defaultVendors: false,
|
|
82
|
+
},
|
|
84
83
|
},
|
|
85
84
|
},
|
|
86
85
|
}
|
package/.vscode/settings.json
DELETED
package/src/.jshintrc
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"maxerr" : 50,
|
|
3
|
-
"bitwise" : true,
|
|
4
|
-
"camelcase" : false,
|
|
5
|
-
"curly" : false,
|
|
6
|
-
"eqeqeq" : true,
|
|
7
|
-
"forin" : true,
|
|
8
|
-
"freeze" : true,
|
|
9
|
-
"immed" : false,
|
|
10
|
-
"latedef" : false,
|
|
11
|
-
"newcap" : false,
|
|
12
|
-
"noarg" : true,
|
|
13
|
-
"noempty" : true,
|
|
14
|
-
"nonbsp" : true,
|
|
15
|
-
"nonew" : false,
|
|
16
|
-
"plusplus" : false,
|
|
17
|
-
"quotmark" : false,
|
|
18
|
-
"undef" : true,
|
|
19
|
-
"unused" : true,
|
|
20
|
-
"strict" : false,
|
|
21
|
-
"maxparams" : false,
|
|
22
|
-
"maxdepth" : false,
|
|
23
|
-
"maxstatements" : false,
|
|
24
|
-
"maxcomplexity" : false,
|
|
25
|
-
"maxlen" : false,
|
|
26
|
-
"varstmt" : false,
|
|
27
|
-
"asi" : false,
|
|
28
|
-
"boss" : false,
|
|
29
|
-
"debug" : false,
|
|
30
|
-
"eqnull" : false,
|
|
31
|
-
"esversion" : 6,
|
|
32
|
-
"moz" : false,
|
|
33
|
-
"evil" : false,
|
|
34
|
-
"expr" : false,
|
|
35
|
-
"funcscope" : false,
|
|
36
|
-
"globalstrict" : false,
|
|
37
|
-
"iterator" : false,
|
|
38
|
-
"lastsemic" : false,
|
|
39
|
-
"laxbreak" : false,
|
|
40
|
-
"laxcomma" : false,
|
|
41
|
-
"loopfunc" : false,
|
|
42
|
-
"multistr" : false,
|
|
43
|
-
"noyield" : false,
|
|
44
|
-
"notypeof" : false,
|
|
45
|
-
"proto" : false,
|
|
46
|
-
"scripturl" : false,
|
|
47
|
-
"shadow" : false,
|
|
48
|
-
"sub" : false,
|
|
49
|
-
"supernew" : false,
|
|
50
|
-
"validthis" : false,
|
|
51
|
-
"browser" : true,
|
|
52
|
-
"browserify" : false,
|
|
53
|
-
"couch" : false,
|
|
54
|
-
"devel" : true,
|
|
55
|
-
"dojo" : false,
|
|
56
|
-
"jasmine" : false,
|
|
57
|
-
"jquery" : false,
|
|
58
|
-
"mocha" : true,
|
|
59
|
-
"mootools" : false,
|
|
60
|
-
"node" : false,
|
|
61
|
-
"nonstandard" : false,
|
|
62
|
-
"phantom" : false,
|
|
63
|
-
"prototypejs" : false,
|
|
64
|
-
"qunit" : false,
|
|
65
|
-
"rhino" : false,
|
|
66
|
-
"shelljs" : false,
|
|
67
|
-
"typed" : false,
|
|
68
|
-
"worker" : false,
|
|
69
|
-
"wsh" : false,
|
|
70
|
-
"yui" : false,
|
|
71
|
-
"globals" : {
|
|
72
|
-
"self" : true,
|
|
73
|
-
"caches" : true
|
|
74
|
-
}
|
|
75
|
-
}
|