@vuepress/plugin-pwa 2.0.0-beta.42 → 2.0.0-beta.45

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.
@@ -0,0 +1,2 @@
1
+ declare const _default: import("@vuepress/client").ClientConfig;
2
+ export default _default;
@@ -0,0 +1,50 @@
1
+ import { defineClientConfig, withBase } from '@vuepress/client';
2
+ import mitt from 'mitt';
3
+ import { onMounted, provide } from 'vue';
4
+ import { pwaEventSymbol } from './composables';
5
+ const swFilename = __PWA_SW_FILENAME__;
6
+ export default defineClientConfig({
7
+ setup() {
8
+ if (__VUEPRESS_SSR__ || !swFilename)
9
+ return;
10
+ const log = (...args) => console.log('[@vuepress/plugin-pwa]', ...args);
11
+ // create event emitter and provide it
12
+ const event = mitt();
13
+ provide(pwaEventSymbol, event);
14
+ onMounted(async () => {
15
+ // lazy load register-service-worker
16
+ const { register } = await import('register-service-worker');
17
+ // Register service worker
18
+ register(withBase(swFilename), {
19
+ ready(registration) {
20
+ log('Service worker is active.');
21
+ event.emit('ready', registration);
22
+ },
23
+ registered(registration) {
24
+ log('Service worker has been registered.');
25
+ event.emit('registered', registration);
26
+ },
27
+ cached(registration) {
28
+ log('Content has been cached for offline use.');
29
+ event.emit('cached', registration);
30
+ },
31
+ updatefound(registration) {
32
+ log('New content is downloading.');
33
+ event.emit('updatefound', registration);
34
+ },
35
+ updated(registration) {
36
+ log('New content is available, please refresh.');
37
+ event.emit('updated', registration);
38
+ },
39
+ offline() {
40
+ log('No internet connection found. App is running in offline mode.');
41
+ event.emit('offline');
42
+ },
43
+ error(err) {
44
+ log('Error during service worker registration:', err);
45
+ event.emit('error', err);
46
+ },
47
+ });
48
+ });
49
+ },
50
+ });
@@ -12,7 +12,7 @@ const pwaPlugin = ({ serviceWorkerFilename = 'service-worker.js', ...generateSWC
12
12
  }
13
13
  return {
14
14
  ...plugin,
15
- clientAppSetupFiles: utils_1.path.resolve(__dirname, '../client/clientAppSetup.js'),
15
+ clientConfigFile: utils_1.path.resolve(__dirname, '../client/config.js'),
16
16
  define: {
17
17
  __PWA_SW_FILENAME__: serviceWorkerFilename,
18
18
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuepress/plugin-pwa",
3
- "version": "2.0.0-beta.42",
3
+ "version": "2.0.0-beta.45",
4
4
  "description": "VuePress plugin - progressive web application",
5
5
  "keywords": [
6
6
  "vuepress-plugin",
@@ -24,13 +24,13 @@
24
24
  "lib"
25
25
  ],
26
26
  "dependencies": {
27
- "@vuepress/client": "2.0.0-beta.42",
28
- "@vuepress/core": "2.0.0-beta.42",
29
- "@vuepress/utils": "2.0.0-beta.42",
27
+ "@vuepress/client": "2.0.0-beta.45",
28
+ "@vuepress/core": "2.0.0-beta.45",
29
+ "@vuepress/utils": "2.0.0-beta.45",
30
30
  "mitt": "^3.0.0",
31
31
  "register-service-worker": "^1.7.2",
32
32
  "vue": "^3.2.33",
33
- "workbox-build": "^6.5.2"
33
+ "workbox-build": "^6.5.3"
34
34
  },
35
35
  "publishConfig": {
36
36
  "access": "public"
@@ -1,2 +0,0 @@
1
- declare const _default: import("@vuepress/client").ClientAppSetup;
2
- export default _default;
@@ -1,48 +0,0 @@
1
- import { defineClientAppSetup, withBase } from '@vuepress/client';
2
- import mitt from 'mitt';
3
- import { onMounted, provide } from 'vue';
4
- import { pwaEventSymbol } from './composables';
5
- const swFilename = __PWA_SW_FILENAME__;
6
- export default defineClientAppSetup(() => {
7
- if (__VUEPRESS_SSR__ || !swFilename)
8
- return;
9
- const log = (...args) => console.log('[@vuepress/plugin-pwa]', ...args);
10
- // create event emitter and provide it
11
- const event = mitt();
12
- provide(pwaEventSymbol, event);
13
- onMounted(async () => {
14
- // lazy load register-service-worker
15
- const { register } = await import('register-service-worker');
16
- // Register service worker
17
- register(withBase(swFilename), {
18
- ready(registration) {
19
- log('Service worker is active.');
20
- event.emit('ready', registration);
21
- },
22
- registered(registration) {
23
- log('Service worker has been registered.');
24
- event.emit('registered', registration);
25
- },
26
- cached(registration) {
27
- log('Content has been cached for offline use.');
28
- event.emit('cached', registration);
29
- },
30
- updatefound(registration) {
31
- log('New content is downloading.');
32
- event.emit('updatefound', registration);
33
- },
34
- updated(registration) {
35
- log('New content is available, please refresh.');
36
- event.emit('updated', registration);
37
- },
38
- offline() {
39
- log('No internet connection found. App is running in offline mode.');
40
- event.emit('offline');
41
- },
42
- error(err) {
43
- log('Error during service worker registration:', err);
44
- event.emit('error', err);
45
- },
46
- });
47
- });
48
- });