@vuepress/plugin-pwa 2.0.0-beta.6 → 2.0.0-beta.60

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
+ export * from './usePwaEvent.js';
2
+ export * from './useSkipWaiting.js';
@@ -0,0 +1,2 @@
1
+ export * from './usePwaEvent.js';
2
+ export * from './useSkipWaiting.js';
@@ -0,0 +1,21 @@
1
+ import type { Emitter } from 'mitt';
2
+ import type { InjectionKey } from 'vue';
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
+ }>;
12
+ export declare const pwaEventSymbol: InjectionKey<PwaEvent>;
13
+ export declare const usePwaEvent: () => Emitter<{
14
+ ready: ServiceWorkerRegistration;
15
+ registered: ServiceWorkerRegistration;
16
+ cached: ServiceWorkerRegistration;
17
+ updatefound: ServiceWorkerRegistration;
18
+ updated: ServiceWorkerRegistration;
19
+ offline: void;
20
+ error: Error;
21
+ }>;
@@ -1,9 +1,9 @@
1
1
  import { inject } from 'vue';
2
2
  export const pwaEventSymbol = Symbol('pwaEvent');
3
3
  export const usePwaEvent = () => {
4
- const pawEvent = inject(pwaEventSymbol);
5
- if (!pawEvent) {
4
+ const pwaEvent = inject(pwaEventSymbol);
5
+ if (!pwaEvent) {
6
6
  throw new Error('usePwaEvent() is called without provider.');
7
7
  }
8
- return pawEvent;
8
+ return pwaEvent;
9
9
  };
@@ -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/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
+ });
@@ -0,0 +1 @@
1
+ export * from './composables/index.js';
@@ -0,0 +1 @@
1
+ export * from './composables/index.js';
@@ -0,0 +1,4 @@
1
+ import type { App } from '@vuepress/core';
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>;
@@ -0,0 +1,36 @@
1
+ import { logger } from '@vuepress/utils';
2
+ const assetsExtensions = [
3
+ // basic
4
+ 'html',
5
+ 'js',
6
+ 'css',
7
+ // images
8
+ 'png',
9
+ 'jpg',
10
+ 'jpeg',
11
+ 'gif',
12
+ 'svg',
13
+ // fonts
14
+ 'woff',
15
+ 'woff2',
16
+ 'eot',
17
+ 'tff',
18
+ 'otf',
19
+ ];
20
+ export const generateServiceWorker = async (app, serviceWorkerFilename, generateSWConfig) => {
21
+ // lazy-load workbox-build
22
+ const { generateSW } = await import('workbox-build');
23
+ const globDirectory = app.dir.dest();
24
+ const swDest = app.dir.dest(serviceWorkerFilename);
25
+ const { warnings } = await generateSW({
26
+ dontCacheBustURLsMatching: new RegExp(`\\.[0-9a-f]{8}\\.(${assetsExtensions.join('|')})$`),
27
+ globPatterns: [`**/*.{${assetsExtensions.join(',')}}`],
28
+ mode: app.env.isDebug ? 'development' : 'production',
29
+ sourcemap: app.env.isDebug,
30
+ ...generateSWConfig,
31
+ // should not be override by user config
32
+ globDirectory,
33
+ swDest,
34
+ });
35
+ warnings.forEach((warning) => logger.warn('[@vuepress/plugin-pwa]', warning));
36
+ };
@@ -0,0 +1,4 @@
1
+ import { pwaPlugin } from './pwaPlugin.js';
2
+ export * from './generateServiceWorker.js';
3
+ export * from './pwaPlugin.js';
4
+ export default pwaPlugin;
@@ -0,0 +1,4 @@
1
+ import { pwaPlugin } from './pwaPlugin.js';
2
+ export * from './generateServiceWorker.js';
3
+ export * from './pwaPlugin.js';
4
+ export default pwaPlugin;
@@ -1,9 +1,9 @@
1
1
  import type { Plugin } from '@vuepress/core';
2
- import type { GenerateSWConfig } from 'workbox-build';
2
+ import type { GenerateSWConfig } from './generateServiceWorker.js';
3
3
  /**
4
4
  * Options for @vuepress/plugin-pwa
5
5
  */
6
- export interface PwaPluginOptions extends Omit<GenerateSWConfig, 'swDest' | 'globDirectory'> {
6
+ export interface PwaPluginOptions extends GenerateSWConfig {
7
7
  /**
8
8
  * Filename of the generated service worker file
9
9
  *
@@ -14,5 +14,4 @@ export interface PwaPluginOptions extends Omit<GenerateSWConfig, 'swDest' | 'glo
14
14
  */
15
15
  serviceWorkerFilename?: string;
16
16
  }
17
- export declare const pwaPlugin: Plugin<PwaPluginOptions>;
18
- export default pwaPlugin;
17
+ export declare const pwaPlugin: ({ serviceWorkerFilename, ...generateSWConfig }?: PwaPluginOptions) => Plugin;
@@ -0,0 +1,19 @@
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-beta.6",
3
+ "version": "2.0.0-beta.60",
4
4
  "description": "VuePress plugin - progressive web application",
5
5
  "keywords": [
6
6
  "vuepress-plugin",
@@ -18,30 +18,31 @@
18
18
  },
19
19
  "license": "MIT",
20
20
  "author": "meteorlxy",
21
- "main": "lib/index.js",
22
- "types": "lib/index.d.ts",
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
- "lib",
25
- "styles"
30
+ "lib"
26
31
  ],
27
- "scripts": {
28
- "build": "tsc -b tsconfig.build.json",
29
- "clean": "rimraf lib *.tsbuildinfo"
30
- },
31
32
  "dependencies": {
32
- "@vuepress/client": "2.0.0-beta.6",
33
- "@vuepress/core": "2.0.0-beta.6",
34
- "@vuepress/utils": "2.0.0-beta.5",
35
- "mitt": "^2.1.0",
33
+ "mitt": "^3.0.0",
36
34
  "register-service-worker": "^1.7.2",
37
- "vue": "^3.0.7",
38
- "workbox-build": "^6.1.2"
39
- },
40
- "devDependencies": {
41
- "@types/workbox-build": "^5.0.0"
35
+ "vue": "^3.2.45",
36
+ "workbox-build": "^6.5.4",
37
+ "@vuepress/client": "2.0.0-beta.60",
38
+ "@vuepress/core": "2.0.0-beta.60",
39
+ "@vuepress/utils": "2.0.0-beta.60"
42
40
  },
43
41
  "publishConfig": {
44
42
  "access": "public"
45
43
  },
46
- "gitHead": "f8cd4a37d251e64ded2f1d7e8ca51afd81fd72d9"
47
- }
44
+ "scripts": {
45
+ "build": "tsc -b tsconfig.build.json",
46
+ "clean": "rimraf lib *.tsbuildinfo"
47
+ }
48
+ }
package/CHANGELOG.md DELETED
@@ -1,163 +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.6](https://github.com/vuepress/vuepress-next/compare/v2.0.0-beta.5...v2.0.0-beta.6) (2021-03-26)
7
-
8
- **Note:** Version bump only for package @vuepress/plugin-pwa
9
-
10
-
11
-
12
-
13
-
14
- # [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)
15
-
16
- **Note:** Version bump only for package @vuepress/plugin-pwa
17
-
18
-
19
-
20
-
21
-
22
- # [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)
23
-
24
- **Note:** Version bump only for package @vuepress/plugin-pwa
25
-
26
-
27
-
28
-
29
-
30
- # [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)
31
-
32
- **Note:** Version bump only for package @vuepress/plugin-pwa
33
-
34
-
35
-
36
-
37
-
38
- # [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)
39
-
40
- **Note:** Version bump only for package @vuepress/plugin-pwa
41
-
42
-
43
-
44
-
45
-
46
- # [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)
47
-
48
- **Note:** Version bump only for package @vuepress/plugin-pwa
49
-
50
-
51
-
52
-
53
-
54
- # [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)
55
-
56
- **Note:** Version bump only for package @vuepress/plugin-pwa
57
-
58
-
59
-
60
-
61
-
62
- # [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)
63
-
64
- **Note:** Version bump only for package @vuepress/plugin-pwa
65
-
66
-
67
-
68
-
69
-
70
- # [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)
71
-
72
- **Note:** Version bump only for package @vuepress/plugin-pwa
73
-
74
-
75
-
76
-
77
-
78
- # [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)
79
-
80
- **Note:** Version bump only for package @vuepress/plugin-pwa
81
-
82
-
83
-
84
-
85
-
86
- # [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)
87
-
88
- **Note:** Version bump only for package @vuepress/plugin-pwa
89
-
90
-
91
-
92
-
93
-
94
- # [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)
95
-
96
- **Note:** Version bump only for package @vuepress/plugin-pwa
97
-
98
-
99
-
100
-
101
-
102
- # [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)
103
-
104
- **Note:** Version bump only for package @vuepress/plugin-pwa
105
-
106
-
107
-
108
-
109
-
110
- # [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)
111
-
112
- **Note:** Version bump only for package @vuepress/plugin-pwa
113
-
114
-
115
-
116
-
117
-
118
- # [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)
119
-
120
- **Note:** Version bump only for package @vuepress/plugin-pwa
121
-
122
-
123
-
124
-
125
-
126
- # [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)
127
-
128
- **Note:** Version bump only for package @vuepress/plugin-pwa
129
-
130
-
131
-
132
-
133
-
134
- # [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)
135
-
136
- **Note:** Version bump only for package @vuepress/plugin-pwa
137
-
138
-
139
-
140
-
141
-
142
- # [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)
143
-
144
- **Note:** Version bump only for package @vuepress/plugin-pwa
145
-
146
-
147
-
148
-
149
-
150
- # [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)
151
-
152
- **Note:** Version bump only for package @vuepress/plugin-pwa
153
-
154
-
155
-
156
-
157
-
158
- # [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)
159
-
160
-
161
- ### Features
162
-
163
- * **plugin-pwa:** migrate pwa plugin ([aa54fd6](https://github.com/vuepress/vuepress-next/commit/aa54fd65aa77b32b97de0a38359f1ad07f96f566))
@@ -1,2 +0,0 @@
1
- declare const _default: import("@vuepress/client").ClientAppSetup;
2
- export default _default;
@@ -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
- });
@@ -1,2 +0,0 @@
1
- export * from './usePwaEvent';
2
- export * from './useSkipWaiting';
@@ -1,2 +0,0 @@
1
- export * from './usePwaEvent';
2
- export * from './useSkipWaiting';
@@ -1,22 +0,0 @@
1
- import type { Emitter, Handler, WildcardHandler } from 'mitt';
2
- import type { InjectionKey } from 'vue';
3
- export interface PwaEvent extends Emitter {
4
- on(type: 'ready', handler: Handler<ServiceWorkerRegistration>): void;
5
- on(type: 'registered', handler: Handler<ServiceWorkerRegistration>): void;
6
- on(type: 'cached', handler: Handler<ServiceWorkerRegistration>): void;
7
- on(type: 'updatefound', handler: Handler<ServiceWorkerRegistration>): void;
8
- on(type: 'updated', handler: Handler<ServiceWorkerRegistration>): void;
9
- on(type: 'offline', handler: Handler<void>): void;
10
- on(type: 'error', handler: Handler<Error>): void;
11
- on(type: '*', handler: WildcardHandler): void;
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
- }
21
- export declare const pwaEventSymbol: InjectionKey<PwaEvent>;
22
- export declare const usePwaEvent: () => PwaEvent;
package/lib/index.js DELETED
@@ -1,50 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pwaPlugin = void 0;
4
- const utils_1 = require("@vuepress/utils");
5
- const assetsExtensions = [
6
- // basic
7
- 'html',
8
- 'js',
9
- 'css',
10
- // images
11
- 'png',
12
- 'jpg',
13
- 'jpeg',
14
- 'gif',
15
- 'svg',
16
- // fonts
17
- 'woff',
18
- 'woff2',
19
- 'eot',
20
- 'tff',
21
- 'otf',
22
- ];
23
- const pwaPlugin = ({ serviceWorkerFilename = 'service-worker.js', ...generateSWConfig }) => ({
24
- name: '@vuepress/plugin-pwa',
25
- clientAppSetupFiles: utils_1.path.resolve(__dirname, './clientAppSetup.js'),
26
- define: {
27
- __PWA_SW_FILENAME__: serviceWorkerFilename,
28
- },
29
- async onGenerated(app) {
30
- await utils_1.withSpinner('Generating service worker')(async () => {
31
- // lazy-load workbox-build
32
- const generateSW = require('workbox-build/build/generate-sw');
33
- const globDirectory = app.dir.dest();
34
- const swDest = app.dir.dest(serviceWorkerFilename);
35
- const { warnings } = await generateSW({
36
- dontCacheBustURLsMatching: new RegExp(`\\.[0-9a-f]{8}\\.(${assetsExtensions.join('|')})$`),
37
- globPatterns: [`**/*.{${assetsExtensions.join(',')}}`],
38
- mode: app.env.isDebug ? 'development' : 'production',
39
- sourcemap: app.env.isDebug,
40
- ...generateSWConfig,
41
- // should not be override by user config
42
- globDirectory,
43
- swDest,
44
- });
45
- warnings.forEach((warning) => utils_1.logger.warn('[@vuepress/plugin-pwa]', warning));
46
- });
47
- },
48
- });
49
- exports.pwaPlugin = pwaPlugin;
50
- exports.default = exports.pwaPlugin;