@cocreate/pwa 1.6.10 → 1.6.12
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/.github/FUNDING.yml +3 -3
- package/.github/workflows/automated.yml +95 -95
- package/.github/workflows/manual.yml +44 -44
- package/CHANGELOG.md +572 -557
- package/CONTRIBUTING.md +96 -96
- package/CoCreate.config.js +26 -26
- package/LICENSE +21 -21
- package/README.md +75 -75
- package/demo/css/style.css +34 -34
- package/demo/css/test1.css +3 -3
- package/demo/css/test2.css +3 -3
- package/demo/css/test3.css +3 -3
- package/demo/index.html +77 -77
- package/demo/js/test1.js +1 -1
- package/demo/js/test2.js +1 -1
- package/demo/js/test3.js +1 -1
- package/demo/manifest.json +91 -91
- package/demo/offline.html +34 -34
- package/demo/pages/test1.html +55 -55
- package/demo/pages/test2.html +55 -55
- package/demo/pages/test3.html +56 -56
- package/demo/sw.js +111 -111
- package/docs/index.html +254 -254
- package/package.json +3 -3
- package/release.config.js +21 -21
- package/src/badging.js +10 -10
- package/src/cache.js +43 -43
- package/src/contact-picker.js +10 -10
- package/src/file-share.js +14 -14
- package/src/index.js +98 -98
- package/src/wakeLock.js +8 -8
- package/src/web-share.js +1 -1
- package/webpack.config.js +84 -84
package/src/cache.js
CHANGED
|
@@ -1,44 +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
|
-
|
|
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
44
|
export {deleteCache, deleteFile}
|
package/src/contact-picker.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
async function getContacts() {
|
|
3
|
-
const properties = ['name', 'email', 'tel'];
|
|
4
|
-
const options = { multiple: true };
|
|
5
|
-
try {
|
|
6
|
-
const contacts = await navigator.contacts.select(properties, options);
|
|
7
|
-
console.log(contacts);
|
|
8
|
-
} catch (ex) {
|
|
9
|
-
// Handle any errors here.
|
|
10
|
-
}
|
|
1
|
+
|
|
2
|
+
async function getContacts() {
|
|
3
|
+
const properties = ['name', 'email', 'tel'];
|
|
4
|
+
const options = { multiple: true };
|
|
5
|
+
try {
|
|
6
|
+
const contacts = await navigator.contacts.select(properties, options);
|
|
7
|
+
console.log(contacts);
|
|
8
|
+
} catch (ex) {
|
|
9
|
+
// Handle any errors here.
|
|
10
|
+
}
|
|
11
11
|
}
|
package/src/file-share.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
// https://web.dev/learn/pwa/os-integration/
|
|
2
|
-
// Have the user select a file.
|
|
3
|
-
const [ handle ] = await window.showOpenFilePicker();
|
|
4
|
-
// Get the File object from the handle.
|
|
5
|
-
const file = await handle.getFile();
|
|
6
|
-
// Get the file content.
|
|
7
|
-
// Also available, slice(), stream(), arrayBuffer()
|
|
8
|
-
const content = await file.text();
|
|
9
|
-
|
|
10
|
-
// Make a writable stream from the handle.
|
|
11
|
-
const writable = await handle.createWritable();
|
|
12
|
-
// Write the contents of the file to the stream.
|
|
13
|
-
await writable.write(contents);
|
|
14
|
-
// Close the file and write the contents to disk.
|
|
1
|
+
// https://web.dev/learn/pwa/os-integration/
|
|
2
|
+
// Have the user select a file.
|
|
3
|
+
const [ handle ] = await window.showOpenFilePicker();
|
|
4
|
+
// Get the File object from the handle.
|
|
5
|
+
const file = await handle.getFile();
|
|
6
|
+
// Get the file content.
|
|
7
|
+
// Also available, slice(), stream(), arrayBuffer()
|
|
8
|
+
const content = await file.text();
|
|
9
|
+
|
|
10
|
+
// Make a writable stream from the handle.
|
|
11
|
+
const writable = await handle.createWritable();
|
|
12
|
+
// Write the contents of the file to the stream.
|
|
13
|
+
await writable.write(contents);
|
|
14
|
+
// Close the file and write the contents to disk.
|
|
15
15
|
await writable.close();
|
package/src/index.js
CHANGED
|
@@ -1,99 +1,99 @@
|
|
|
1
|
-
import {deleteCache, deleteFile} from './cache.js'
|
|
2
|
-
import localStorage from '@cocreate/local-storage'
|
|
3
|
-
|
|
4
|
-
const button = document.querySelector('[actions*="install"]');
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Warn the page must be served over HTTPS
|
|
8
|
-
* The `beforeinstallprompt` event won't fire if the page is served over HTTP.
|
|
9
|
-
* Installability requires a service worker with a fetch event handler, and
|
|
10
|
-
* if the page isn't served over HTTPS, the service worker won't load.
|
|
11
|
-
*/
|
|
12
|
-
// if (window.location.protocol === 'http:') {
|
|
13
|
-
// const requireHTTPS = document.getElementById('requireHTTPS');
|
|
14
|
-
// const link = requireHTTPS.querySelector('a');
|
|
15
|
-
// link.href = window.location.href.replace('http://', 'https://');
|
|
16
|
-
// requireHTTPS.classList.remove('hidden');
|
|
17
|
-
// }
|
|
18
|
-
|
|
19
|
-
window.addEventListener('beforeinstallprompt', (event) => {
|
|
20
|
-
// console.log('👍', 'beforeinstallprompt', event);
|
|
21
|
-
// Stash the event so it can be triggered later.
|
|
22
|
-
window.deferredPrompt = event;
|
|
23
|
-
// Remove the 'hidden' class from the install button container
|
|
24
|
-
if (button)
|
|
25
|
-
button.removeAttribute('hidden');
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
if (button) {
|
|
29
|
-
button.addEventListener('click', async() => {
|
|
30
|
-
// console.log('👍', 'installBtn-clicked');
|
|
31
|
-
const promptEvent = window.deferredPrompt;
|
|
32
|
-
if (!promptEvent) {
|
|
33
|
-
// The deferred prompt isn't available.
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
// Show the install prompt.
|
|
37
|
-
promptEvent.prompt();
|
|
38
|
-
// Log the result
|
|
39
|
-
const result = await promptEvent.userChoice;
|
|
40
|
-
console.log('👍', 'userChoice', result);
|
|
41
|
-
// Reset the deferred prompt variable, since
|
|
42
|
-
// prompt() can only be called once.
|
|
43
|
-
window.deferredPrompt = null;
|
|
44
|
-
// Hide the install button.
|
|
45
|
-
button.addAttribute('hidden', '');
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
window.addEventListener('appinstalled', (event) => {
|
|
50
|
-
// console.log('👍', 'appinstalled', event);
|
|
51
|
-
// Clear the deferredPrompt so it can be garbage collected
|
|
52
|
-
window.deferredPrompt = null;
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
async function persistData() {
|
|
56
|
-
if (navigator.storage && navigator.storage.persist) {
|
|
57
|
-
const result = await navigator.storage.persist();
|
|
58
|
-
// console.log(`Data persisted: ${result}`);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if ('serviceWorker' in navigator) {
|
|
63
|
-
let workerPath
|
|
64
|
-
if (window.CoCreateConfig && window.CoCreateConfig.serviceWorker)
|
|
65
|
-
workerPath = window.CoCreateConfig.serviceWorker
|
|
66
|
-
else
|
|
67
|
-
workerPath = localStorage.getItem("serviceWorker") || '/sw.js'
|
|
68
|
-
|
|
69
|
-
localStorage.setItem("serviceWorker", workerPath);
|
|
70
|
-
|
|
71
|
-
let isPwa = true
|
|
72
|
-
if (workerPath) {
|
|
73
|
-
navigator.serviceWorker.getRegistrations().then(registrations => {
|
|
74
|
-
if (registrations.length === 0 || isPwa == true)
|
|
75
|
-
window.addEventListener("load", function(event) {
|
|
76
|
-
navigator.serviceWorker.getRegistration(workerPath).then(registration => {
|
|
77
|
-
if (registration && registration.active) {
|
|
78
|
-
console.log('Service Worker Active')
|
|
79
|
-
} else {
|
|
80
|
-
navigator.serviceWorker.register(workerPath)
|
|
81
|
-
.then(reg => {
|
|
82
|
-
reg.onupdatefound = () => {
|
|
83
|
-
const installingWorker = reg.installing;
|
|
84
|
-
installingWorker.onstatechange = () => {
|
|
85
|
-
// console.log('Service Worker', installingWorker.state);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
})
|
|
89
|
-
.catch(err => console.log('SW ERROR', err));
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
|
|
1
|
+
import {deleteCache, deleteFile} from './cache.js'
|
|
2
|
+
import localStorage from '@cocreate/local-storage'
|
|
3
|
+
|
|
4
|
+
const button = document.querySelector('[actions*="install"]');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Warn the page must be served over HTTPS
|
|
8
|
+
* The `beforeinstallprompt` event won't fire if the page is served over HTTP.
|
|
9
|
+
* Installability requires a service worker with a fetch event handler, and
|
|
10
|
+
* if the page isn't served over HTTPS, the service worker won't load.
|
|
11
|
+
*/
|
|
12
|
+
// if (window.location.protocol === 'http:') {
|
|
13
|
+
// const requireHTTPS = document.getElementById('requireHTTPS');
|
|
14
|
+
// const link = requireHTTPS.querySelector('a');
|
|
15
|
+
// link.href = window.location.href.replace('http://', 'https://');
|
|
16
|
+
// requireHTTPS.classList.remove('hidden');
|
|
17
|
+
// }
|
|
18
|
+
|
|
19
|
+
window.addEventListener('beforeinstallprompt', (event) => {
|
|
20
|
+
// console.log('👍', 'beforeinstallprompt', event);
|
|
21
|
+
// Stash the event so it can be triggered later.
|
|
22
|
+
window.deferredPrompt = event;
|
|
23
|
+
// Remove the 'hidden' class from the install button container
|
|
24
|
+
if (button)
|
|
25
|
+
button.removeAttribute('hidden');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
if (button) {
|
|
29
|
+
button.addEventListener('click', async() => {
|
|
30
|
+
// console.log('👍', 'installBtn-clicked');
|
|
31
|
+
const promptEvent = window.deferredPrompt;
|
|
32
|
+
if (!promptEvent) {
|
|
33
|
+
// The deferred prompt isn't available.
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
// Show the install prompt.
|
|
37
|
+
promptEvent.prompt();
|
|
38
|
+
// Log the result
|
|
39
|
+
const result = await promptEvent.userChoice;
|
|
40
|
+
console.log('👍', 'userChoice', result);
|
|
41
|
+
// Reset the deferred prompt variable, since
|
|
42
|
+
// prompt() can only be called once.
|
|
43
|
+
window.deferredPrompt = null;
|
|
44
|
+
// Hide the install button.
|
|
45
|
+
button.addAttribute('hidden', '');
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
window.addEventListener('appinstalled', (event) => {
|
|
50
|
+
// console.log('👍', 'appinstalled', event);
|
|
51
|
+
// Clear the deferredPrompt so it can be garbage collected
|
|
52
|
+
window.deferredPrompt = null;
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
async function persistData() {
|
|
56
|
+
if (navigator.storage && navigator.storage.persist) {
|
|
57
|
+
const result = await navigator.storage.persist();
|
|
58
|
+
// console.log(`Data persisted: ${result}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if ('serviceWorker' in navigator) {
|
|
63
|
+
let workerPath
|
|
64
|
+
if (window.CoCreateConfig && window.CoCreateConfig.serviceWorker)
|
|
65
|
+
workerPath = window.CoCreateConfig.serviceWorker
|
|
66
|
+
else
|
|
67
|
+
workerPath = localStorage.getItem("serviceWorker") || '/sw.js'
|
|
68
|
+
|
|
69
|
+
localStorage.setItem("serviceWorker", workerPath);
|
|
70
|
+
|
|
71
|
+
let isPwa = true
|
|
72
|
+
if (workerPath) {
|
|
73
|
+
navigator.serviceWorker.getRegistrations().then(registrations => {
|
|
74
|
+
if (registrations.length === 0 || isPwa == true)
|
|
75
|
+
window.addEventListener("load", function(event) {
|
|
76
|
+
navigator.serviceWorker.getRegistration(workerPath).then(registration => {
|
|
77
|
+
if (registration && registration.active) {
|
|
78
|
+
console.log('Service Worker Active')
|
|
79
|
+
} else {
|
|
80
|
+
navigator.serviceWorker.register(workerPath)
|
|
81
|
+
.then(reg => {
|
|
82
|
+
reg.onupdatefound = () => {
|
|
83
|
+
const installingWorker = reg.installing;
|
|
84
|
+
installingWorker.onstatechange = () => {
|
|
85
|
+
// console.log('Service Worker', installingWorker.state);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
})
|
|
89
|
+
.catch(err => console.log('SW ERROR', err));
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
|
|
99
99
|
export default {deleteCache, deleteFile, persistData}
|
package/src/wakeLock.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
// Request a screen wake lock
|
|
2
|
-
const wakeLock = await navigator.wakeLock.request();
|
|
3
|
-
|
|
4
|
-
// Listen for wake lock release
|
|
5
|
-
wakeLock.addEventListener('release', () => {
|
|
6
|
-
console.log(`Screen Wake Lock released: ${wakeLock.released}`);
|
|
7
|
-
});
|
|
8
|
-
// Manually release the wake lock
|
|
1
|
+
// Request a screen wake lock
|
|
2
|
+
const wakeLock = await navigator.wakeLock.request();
|
|
3
|
+
|
|
4
|
+
// Listen for wake lock release
|
|
5
|
+
wakeLock.addEventListener('release', () => {
|
|
6
|
+
console.log(`Screen Wake Lock released: ${wakeLock.released}`);
|
|
7
|
+
});
|
|
8
|
+
// Manually release the wake lock
|
|
9
9
|
wakeLock.release();
|
package/src/web-share.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
// https://web.dev/web-share-target/
|
|
1
|
+
// https://web.dev/web-share-target/
|
package/webpack.config.js
CHANGED
|
@@ -1,84 +1,84 @@
|
|
|
1
|
-
const path = require("path")
|
|
2
|
-
const TerserPlugin = require("terser-webpack-plugin")
|
|
3
|
-
const MiniCssExtractPlugin = require("mini-css-extract-plugin")
|
|
4
|
-
let isProduction = process.env.NODE_ENV === "production"
|
|
5
|
-
const { CleanWebpackPlugin } = require("clean-webpack-plugin")
|
|
6
|
-
|
|
7
|
-
module.exports = {
|
|
8
|
-
entry: {
|
|
9
|
-
"CoCreate-pwa": "./src/index.js",
|
|
10
|
-
},
|
|
11
|
-
output: {
|
|
12
|
-
path: path.resolve(__dirname, "dist"),
|
|
13
|
-
filename: isProduction ? "[name].min.js" : "[name].js",
|
|
14
|
-
libraryTarget: "umd",
|
|
15
|
-
libraryExport: "default",
|
|
16
|
-
library: ["CoCreate", "pwa"],
|
|
17
|
-
globalObject: "this",
|
|
18
|
-
},
|
|
19
|
-
|
|
20
|
-
plugins: [
|
|
21
|
-
new CleanWebpackPlugin(),
|
|
22
|
-
new MiniCssExtractPlugin({
|
|
23
|
-
filename: "[name].css",
|
|
24
|
-
}),
|
|
25
|
-
],
|
|
26
|
-
// Default mode for Webpack is production.
|
|
27
|
-
// Depending on mode Webpack will apply different things
|
|
28
|
-
// on final bundle. For now we don't need production's JavaScript
|
|
29
|
-
// minifying and other thing so let's set mode to development
|
|
30
|
-
mode: isProduction ? "production" : "development",
|
|
31
|
-
module: {
|
|
32
|
-
rules: [
|
|
33
|
-
{
|
|
34
|
-
test: /.js$/,
|
|
35
|
-
exclude: /(node_modules)/,
|
|
36
|
-
use: {
|
|
37
|
-
loader: "babel-loader",
|
|
38
|
-
options: {
|
|
39
|
-
plugins: ["@babel/plugin-transform-modules-commonjs"],
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
test: /.css$/i,
|
|
45
|
-
use: [
|
|
46
|
-
{ loader: "style-loader", options: { injectType: "linkTag" } },
|
|
47
|
-
"file-loader",
|
|
48
|
-
],
|
|
49
|
-
},
|
|
50
|
-
],
|
|
51
|
-
},
|
|
52
|
-
|
|
53
|
-
// add source map
|
|
54
|
-
...(isProduction ? {} : { devtool: "eval-source-map" }),
|
|
55
|
-
|
|
56
|
-
optimization: {
|
|
57
|
-
minimize: true,
|
|
58
|
-
minimizer: [
|
|
59
|
-
new TerserPlugin({
|
|
60
|
-
extractComments: true,
|
|
61
|
-
// cache: true,
|
|
62
|
-
parallel: true,
|
|
63
|
-
// sourceMap: true, // Must be set to true if using source-maps in production
|
|
64
|
-
terserOptions: {
|
|
65
|
-
// https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
|
|
66
|
-
// extractComments: 'all',
|
|
67
|
-
compress: {
|
|
68
|
-
drop_console: true,
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
}),
|
|
72
|
-
],
|
|
73
|
-
splitChunks: {
|
|
74
|
-
chunks: "all",
|
|
75
|
-
minSize: 200,
|
|
76
|
-
// maxSize: 99999,
|
|
77
|
-
//minChunks: 1,
|
|
78
|
-
|
|
79
|
-
cacheGroups: {
|
|
80
|
-
defaultVendors: false,
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
}
|
|
1
|
+
const path = require("path")
|
|
2
|
+
const TerserPlugin = require("terser-webpack-plugin")
|
|
3
|
+
const MiniCssExtractPlugin = require("mini-css-extract-plugin")
|
|
4
|
+
let isProduction = process.env.NODE_ENV === "production"
|
|
5
|
+
const { CleanWebpackPlugin } = require("clean-webpack-plugin")
|
|
6
|
+
|
|
7
|
+
module.exports = {
|
|
8
|
+
entry: {
|
|
9
|
+
"CoCreate-pwa": "./src/index.js",
|
|
10
|
+
},
|
|
11
|
+
output: {
|
|
12
|
+
path: path.resolve(__dirname, "dist"),
|
|
13
|
+
filename: isProduction ? "[name].min.js" : "[name].js",
|
|
14
|
+
libraryTarget: "umd",
|
|
15
|
+
libraryExport: "default",
|
|
16
|
+
library: ["CoCreate", "pwa"],
|
|
17
|
+
globalObject: "this",
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
plugins: [
|
|
21
|
+
new CleanWebpackPlugin(),
|
|
22
|
+
new MiniCssExtractPlugin({
|
|
23
|
+
filename: "[name].css",
|
|
24
|
+
}),
|
|
25
|
+
],
|
|
26
|
+
// Default mode for Webpack is production.
|
|
27
|
+
// Depending on mode Webpack will apply different things
|
|
28
|
+
// on final bundle. For now we don't need production's JavaScript
|
|
29
|
+
// minifying and other thing so let's set mode to development
|
|
30
|
+
mode: isProduction ? "production" : "development",
|
|
31
|
+
module: {
|
|
32
|
+
rules: [
|
|
33
|
+
{
|
|
34
|
+
test: /.js$/,
|
|
35
|
+
exclude: /(node_modules)/,
|
|
36
|
+
use: {
|
|
37
|
+
loader: "babel-loader",
|
|
38
|
+
options: {
|
|
39
|
+
plugins: ["@babel/plugin-transform-modules-commonjs"],
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
test: /.css$/i,
|
|
45
|
+
use: [
|
|
46
|
+
{ loader: "style-loader", options: { injectType: "linkTag" } },
|
|
47
|
+
"file-loader",
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
// add source map
|
|
54
|
+
...(isProduction ? {} : { devtool: "eval-source-map" }),
|
|
55
|
+
|
|
56
|
+
optimization: {
|
|
57
|
+
minimize: true,
|
|
58
|
+
minimizer: [
|
|
59
|
+
new TerserPlugin({
|
|
60
|
+
extractComments: true,
|
|
61
|
+
// cache: true,
|
|
62
|
+
parallel: true,
|
|
63
|
+
// sourceMap: true, // Must be set to true if using source-maps in production
|
|
64
|
+
terserOptions: {
|
|
65
|
+
// https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
|
|
66
|
+
// extractComments: 'all',
|
|
67
|
+
compress: {
|
|
68
|
+
drop_console: true,
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
}),
|
|
72
|
+
],
|
|
73
|
+
splitChunks: {
|
|
74
|
+
chunks: "all",
|
|
75
|
+
minSize: 200,
|
|
76
|
+
// maxSize: 99999,
|
|
77
|
+
//minChunks: 1,
|
|
78
|
+
|
|
79
|
+
cacheGroups: {
|
|
80
|
+
defaultVendors: false,
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
}
|