@vuepress/plugin-pwa 2.0.0-beta.9 → 2.0.0-rc.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/lib/client/composables/index.d.ts +2 -2
- package/lib/client/composables/index.js +2 -2
- package/lib/client/composables/usePwaEvent.d.ts +10 -19
- package/lib/client/composables/usePwaEvent.js +3 -3
- package/lib/client/config.d.ts +2 -0
- package/lib/client/config.js +50 -0
- package/lib/client/index.d.ts +1 -1
- package/lib/client/index.js +1 -1
- package/lib/node/generateServiceWorker.d.ts +3 -2
- package/lib/node/generateServiceWorker.js +4 -8
- package/lib/node/index.d.ts +3 -3
- package/lib/node/index.js +4 -16
- package/lib/node/pwaPlugin.d.ts +3 -3
- package/lib/node/pwaPlugin.js +19 -14
- package/package.json +20 -18
- package/CHANGELOG.md +0 -198
- package/lib/client/clientAppSetup.d.ts +0 -2
- package/lib/client/clientAppSetup.js +0 -48
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './usePwaEvent';
|
|
2
|
-
export * from './useSkipWaiting';
|
|
1
|
+
export * from './usePwaEvent.js';
|
|
2
|
+
export * from './useSkipWaiting.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './usePwaEvent';
|
|
2
|
-
export * from './useSkipWaiting';
|
|
1
|
+
export * from './usePwaEvent.js';
|
|
2
|
+
export * from './useSkipWaiting.js';
|
|
@@ -1,22 +1,13 @@
|
|
|
1
|
-
import type { Emitter
|
|
1
|
+
import type { Emitter } from 'mitt';
|
|
2
2
|
import type { InjectionKey } from 'vue';
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
emit(type: 'ready', event: ServiceWorkerRegistration): void;
|
|
13
|
-
emit(type: 'registered', event: ServiceWorkerRegistration): void;
|
|
14
|
-
emit(type: 'cached', event: ServiceWorkerRegistration): void;
|
|
15
|
-
emit(type: 'updatefound', event: ServiceWorkerRegistration): void;
|
|
16
|
-
emit(type: 'updated', event: ServiceWorkerRegistration): void;
|
|
17
|
-
emit(type: 'offline'): void;
|
|
18
|
-
emit(type: 'error', event: Error): void;
|
|
19
|
-
emit(type: '*', event?: any): void;
|
|
20
|
-
}
|
|
3
|
+
export type PwaEvent = Emitter<{
|
|
4
|
+
ready: ServiceWorkerRegistration;
|
|
5
|
+
registered: ServiceWorkerRegistration;
|
|
6
|
+
cached: ServiceWorkerRegistration;
|
|
7
|
+
updatefound: ServiceWorkerRegistration;
|
|
8
|
+
updated: ServiceWorkerRegistration;
|
|
9
|
+
offline: void;
|
|
10
|
+
error: Error;
|
|
11
|
+
}>;
|
|
21
12
|
export declare const pwaEventSymbol: InjectionKey<PwaEvent>;
|
|
22
13
|
export declare const usePwaEvent: () => PwaEvent;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { inject } from 'vue';
|
|
2
2
|
export const pwaEventSymbol = Symbol('pwaEvent');
|
|
3
3
|
export const usePwaEvent = () => {
|
|
4
|
-
const
|
|
5
|
-
if (!
|
|
4
|
+
const pwaEvent = inject(pwaEventSymbol);
|
|
5
|
+
if (!pwaEvent) {
|
|
6
6
|
throw new Error('usePwaEvent() is called without provider.');
|
|
7
7
|
}
|
|
8
|
-
return
|
|
8
|
+
return pwaEvent;
|
|
9
9
|
};
|
|
@@ -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/index.js';
|
|
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
|
+
});
|
package/lib/client/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './composables';
|
|
1
|
+
export * from './composables/index.js';
|
package/lib/client/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './composables';
|
|
1
|
+
export * from './composables/index.js';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { App } from '@vuepress/core';
|
|
2
|
-
import type {
|
|
3
|
-
export
|
|
2
|
+
import type { GenerateSWOptions } from 'workbox-build';
|
|
3
|
+
export type GenerateSWConfig = Omit<GenerateSWOptions, 'swDest' | 'globDirectory'>;
|
|
4
|
+
export declare const generateServiceWorker: (app: App, serviceWorkerFilename: string, generateSWConfig: GenerateSWConfig) => Promise<void>;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateServiceWorker = void 0;
|
|
4
|
-
const utils_1 = require("@vuepress/utils");
|
|
1
|
+
import { logger } from '@vuepress/utils';
|
|
5
2
|
const assetsExtensions = [
|
|
6
3
|
// basic
|
|
7
4
|
'html',
|
|
@@ -20,9 +17,9 @@ const assetsExtensions = [
|
|
|
20
17
|
'tff',
|
|
21
18
|
'otf',
|
|
22
19
|
];
|
|
23
|
-
const generateServiceWorker = async (app, serviceWorkerFilename, generateSWConfig) => {
|
|
20
|
+
export const generateServiceWorker = async (app, serviceWorkerFilename, generateSWConfig) => {
|
|
24
21
|
// lazy-load workbox-build
|
|
25
|
-
const generateSW =
|
|
22
|
+
const { generateSW } = await import('workbox-build');
|
|
26
23
|
const globDirectory = app.dir.dest();
|
|
27
24
|
const swDest = app.dir.dest(serviceWorkerFilename);
|
|
28
25
|
const { warnings } = await generateSW({
|
|
@@ -35,6 +32,5 @@ const generateServiceWorker = async (app, serviceWorkerFilename, generateSWConfi
|
|
|
35
32
|
globDirectory,
|
|
36
33
|
swDest,
|
|
37
34
|
});
|
|
38
|
-
warnings.forEach((warning) =>
|
|
35
|
+
warnings.forEach((warning) => logger.warn('[@vuepress/plugin-pwa]', warning));
|
|
39
36
|
};
|
|
40
|
-
exports.generateServiceWorker = generateServiceWorker;
|
package/lib/node/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { pwaPlugin } from './pwaPlugin';
|
|
2
|
-
export * from './generateServiceWorker';
|
|
3
|
-
export * from './pwaPlugin';
|
|
1
|
+
import { pwaPlugin } from './pwaPlugin.js';
|
|
2
|
+
export * from './generateServiceWorker.js';
|
|
3
|
+
export * from './pwaPlugin.js';
|
|
4
4
|
export default pwaPlugin;
|
package/lib/node/index.js
CHANGED
|
@@ -1,16 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
const pwaPlugin_1 = require("./pwaPlugin");
|
|
14
|
-
__exportStar(require("./generateServiceWorker"), exports);
|
|
15
|
-
__exportStar(require("./pwaPlugin"), exports);
|
|
16
|
-
exports.default = pwaPlugin_1.pwaPlugin;
|
|
1
|
+
import { pwaPlugin } from './pwaPlugin.js';
|
|
2
|
+
export * from './generateServiceWorker.js';
|
|
3
|
+
export * from './pwaPlugin.js';
|
|
4
|
+
export default pwaPlugin;
|
package/lib/node/pwaPlugin.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Plugin } from '@vuepress/core';
|
|
2
|
-
import type { GenerateSWConfig } from '
|
|
2
|
+
import type { GenerateSWConfig } from './generateServiceWorker.js';
|
|
3
3
|
/**
|
|
4
4
|
* Options for @vuepress/plugin-pwa
|
|
5
5
|
*/
|
|
6
|
-
export interface PwaPluginOptions extends
|
|
6
|
+
export interface PwaPluginOptions extends GenerateSWConfig {
|
|
7
7
|
/**
|
|
8
8
|
* Filename of the generated service worker file
|
|
9
9
|
*
|
|
@@ -14,4 +14,4 @@ export interface PwaPluginOptions extends Omit<GenerateSWConfig, 'swDest' | 'glo
|
|
|
14
14
|
*/
|
|
15
15
|
serviceWorkerFilename?: string;
|
|
16
16
|
}
|
|
17
|
-
export declare const pwaPlugin: Plugin
|
|
17
|
+
export declare const pwaPlugin: ({ serviceWorkerFilename, ...generateSWConfig }?: PwaPluginOptions) => Plugin;
|
package/lib/node/pwaPlugin.js
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { getDirname, path, withSpinner } from '@vuepress/utils';
|
|
2
|
+
import { generateServiceWorker } from './generateServiceWorker.js';
|
|
3
|
+
const __dirname = getDirname(import.meta.url);
|
|
4
|
+
export const pwaPlugin = ({ serviceWorkerFilename = 'service-worker.js', ...generateSWConfig } = {}) => (app) => {
|
|
5
|
+
const plugin = {
|
|
6
|
+
name: '@vuepress/plugin-pwa',
|
|
7
|
+
};
|
|
8
|
+
if (app.env.isDev) {
|
|
9
|
+
return plugin;
|
|
10
|
+
}
|
|
11
|
+
return {
|
|
12
|
+
...plugin,
|
|
13
|
+
clientConfigFile: path.resolve(__dirname, '../client/config.js'),
|
|
14
|
+
define: {
|
|
15
|
+
__PWA_SW_FILENAME__: serviceWorkerFilename,
|
|
16
|
+
},
|
|
17
|
+
onGenerated: (app) => withSpinner('Generating service worker')(() => generateServiceWorker(app, serviceWorkerFilename, generateSWConfig)),
|
|
18
|
+
};
|
|
19
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vuepress/plugin-pwa",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-rc.0",
|
|
4
4
|
"description": "VuePress plugin - progressive web application",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vuepress-plugin",
|
|
@@ -18,29 +18,31 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"author": "meteorlxy",
|
|
21
|
-
"
|
|
22
|
-
"
|
|
21
|
+
"type": "module",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": "./lib/node/index.js",
|
|
24
|
+
"./client": "./lib/client/index.js",
|
|
25
|
+
"./package.json": "./package.json"
|
|
26
|
+
},
|
|
27
|
+
"main": "./lib/node/index.js",
|
|
28
|
+
"types": "./lib/node/index.d.ts",
|
|
23
29
|
"files": [
|
|
24
30
|
"lib"
|
|
25
31
|
],
|
|
26
|
-
"scripts": {
|
|
27
|
-
"build": "tsc -b tsconfig.build.json",
|
|
28
|
-
"clean": "rimraf lib *.tsbuildinfo"
|
|
29
|
-
},
|
|
30
32
|
"dependencies": {
|
|
31
|
-
"
|
|
32
|
-
"@vuepress/core": "2.0.0-beta.9",
|
|
33
|
-
"@vuepress/utils": "2.0.0-beta.8",
|
|
34
|
-
"mitt": "^2.1.0",
|
|
33
|
+
"mitt": "^3.0.1",
|
|
35
34
|
"register-service-worker": "^1.7.2",
|
|
36
|
-
"vue": "^3.
|
|
37
|
-
"workbox-build": "^
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"@
|
|
35
|
+
"vue": "^3.3.8",
|
|
36
|
+
"workbox-build": "^7.0.0",
|
|
37
|
+
"@vuepress/client": "2.0.0-rc.0",
|
|
38
|
+
"@vuepress/core": "2.0.0-rc.0",
|
|
39
|
+
"@vuepress/utils": "2.0.0-rc.0"
|
|
41
40
|
},
|
|
42
41
|
"publishConfig": {
|
|
43
42
|
"access": "public"
|
|
44
43
|
},
|
|
45
|
-
"
|
|
46
|
-
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsc -b tsconfig.build.json",
|
|
46
|
+
"clean": "rimraf lib *.tsbuildinfo"
|
|
47
|
+
}
|
|
48
|
+
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
# Change Log
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
-
|
|
6
|
-
# [2.0.0-beta.9](https://github.com/vuepress/vuepress-next/compare/v2.0.0-beta.8...v2.0.0-beta.9) (2021-04-21)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
### Features
|
|
10
|
-
|
|
11
|
-
* **client:** provide client types file ([89a32b5](https://github.com/vuepress/vuepress-next/commit/89a32b50767ef82556f5ae3300ec016e0acaf0e5))
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
# [2.0.0-beta.8](https://github.com/vuepress/vuepress-next/compare/v2.0.0-beta.7...v2.0.0-beta.8) (2021-04-11)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
### Code Refactoring
|
|
21
|
-
|
|
22
|
-
* normalize themes and plugins structure ([7781172](https://github.com/vuepress/vuepress-next/commit/77811722401bf1ed1fec44c64158ab0cd1ab3179))
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
### BREAKING CHANGES
|
|
26
|
-
|
|
27
|
-
* client API that provided by plugins should be imported from `plugin-foo/lib/client`
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
# [2.0.0-beta.7](https://github.com/vuepress/vuepress-next/compare/v2.0.0-beta.6...v2.0.0-beta.7) (2021-04-09)
|
|
34
|
-
|
|
35
|
-
**Note:** Version bump only for package @vuepress/plugin-pwa
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
# [2.0.0-beta.6](https://github.com/vuepress/vuepress-next/compare/v2.0.0-beta.5...v2.0.0-beta.6) (2021-03-26)
|
|
42
|
-
|
|
43
|
-
**Note:** Version bump only for package @vuepress/plugin-pwa
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
# [2.0.0-beta.5](https://github.com/vuepress/vuepress-next/compare/v2.0.0-beta.4...v2.0.0-beta.5) (2021-03-26)
|
|
50
|
-
|
|
51
|
-
**Note:** Version bump only for package @vuepress/plugin-pwa
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
# [2.0.0-beta.4](https://github.com/vuepress/vuepress-next/compare/v2.0.0-beta.3...v2.0.0-beta.4) (2021-03-20)
|
|
58
|
-
|
|
59
|
-
**Note:** Version bump only for package @vuepress/plugin-pwa
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
# [2.0.0-beta.1](https://github.com/vuepress/vuepress-next/compare/v2.0.0-beta.0...v2.0.0-beta.1) (2021-03-13)
|
|
66
|
-
|
|
67
|
-
**Note:** Version bump only for package @vuepress/plugin-pwa
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
# [2.0.0-beta.0](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.26...v2.0.0-beta.0) (2021-03-13)
|
|
74
|
-
|
|
75
|
-
**Note:** Version bump only for package @vuepress/plugin-pwa
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
# [2.0.0-alpha.25](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.24...v2.0.0-alpha.25) (2021-02-20)
|
|
82
|
-
|
|
83
|
-
**Note:** Version bump only for package @vuepress/plugin-pwa
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
# [2.0.0-alpha.24](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.23...v2.0.0-alpha.24) (2021-02-13)
|
|
90
|
-
|
|
91
|
-
**Note:** Version bump only for package @vuepress/plugin-pwa
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
# [2.0.0-alpha.23](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.22...v2.0.0-alpha.23) (2021-02-10)
|
|
98
|
-
|
|
99
|
-
**Note:** Version bump only for package @vuepress/plugin-pwa
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
# [2.0.0-alpha.22](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.21...v2.0.0-alpha.22) (2021-02-10)
|
|
106
|
-
|
|
107
|
-
**Note:** Version bump only for package @vuepress/plugin-pwa
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
# [2.0.0-alpha.20](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.19...v2.0.0-alpha.20) (2021-02-04)
|
|
114
|
-
|
|
115
|
-
**Note:** Version bump only for package @vuepress/plugin-pwa
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
# [2.0.0-alpha.19](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.18...v2.0.0-alpha.19) (2021-01-24)
|
|
122
|
-
|
|
123
|
-
**Note:** Version bump only for package @vuepress/plugin-pwa
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
# [2.0.0-alpha.18](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.17...v2.0.0-alpha.18) (2021-01-17)
|
|
130
|
-
|
|
131
|
-
**Note:** Version bump only for package @vuepress/plugin-pwa
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
# [2.0.0-alpha.17](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.16...v2.0.0-alpha.17) (2021-01-13)
|
|
138
|
-
|
|
139
|
-
**Note:** Version bump only for package @vuepress/plugin-pwa
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
# [2.0.0-alpha.16](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.15...v2.0.0-alpha.16) (2021-01-11)
|
|
146
|
-
|
|
147
|
-
**Note:** Version bump only for package @vuepress/plugin-pwa
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
# [2.0.0-alpha.15](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.14...v2.0.0-alpha.15) (2021-01-04)
|
|
154
|
-
|
|
155
|
-
**Note:** Version bump only for package @vuepress/plugin-pwa
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
# [2.0.0-alpha.14](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.13...v2.0.0-alpha.14) (2021-01-03)
|
|
162
|
-
|
|
163
|
-
**Note:** Version bump only for package @vuepress/plugin-pwa
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
# [2.0.0-alpha.13](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.12...v2.0.0-alpha.13) (2020-12-23)
|
|
170
|
-
|
|
171
|
-
**Note:** Version bump only for package @vuepress/plugin-pwa
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
# [2.0.0-alpha.12](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.11...v2.0.0-alpha.12) (2020-12-19)
|
|
178
|
-
|
|
179
|
-
**Note:** Version bump only for package @vuepress/plugin-pwa
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
# [2.0.0-alpha.9](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.8...v2.0.0-alpha.9) (2020-12-16)
|
|
186
|
-
|
|
187
|
-
**Note:** Version bump only for package @vuepress/plugin-pwa
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
# [2.0.0-alpha.8](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.7...v2.0.0-alpha.8) (2020-12-11)
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
### Features
|
|
197
|
-
|
|
198
|
-
* **plugin-pwa:** migrate pwa plugin ([aa54fd6](https://github.com/vuepress/vuepress-next/commit/aa54fd65aa77b32b97de0a38359f1ad07f96f566))
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import mitt from 'mitt';
|
|
2
|
-
import { onMounted, provide } from 'vue';
|
|
3
|
-
import { defineClientAppSetup, withBase } from '@vuepress/client';
|
|
4
|
-
import { pwaEventSymbol } from './composables';
|
|
5
|
-
const swFilename = __PWA_SW_FILENAME__;
|
|
6
|
-
export default defineClientAppSetup(() => {
|
|
7
|
-
if (__DEV__ || __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
|
-
});
|