@vuepress/plugin-pwa 2.0.0-beta.48 → 2.0.0-beta.50-pre
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/package.json +15 -9
- package/lib/client/composables/index.d.ts +0 -2
- package/lib/client/composables/index.js +0 -2
- package/lib/client/composables/usePwaEvent.d.ts +0 -13
- package/lib/client/composables/usePwaEvent.js +0 -9
- package/lib/client/composables/useSkipWaiting.d.ts +0 -4
- package/lib/client/composables/useSkipWaiting.js +0 -13
- package/lib/client/config.d.ts +0 -2
- package/lib/client/config.js +0 -50
- package/lib/client/index.d.ts +0 -1
- package/lib/client/index.js +0 -1
- package/lib/node/generateServiceWorker.d.ts +0 -4
- package/lib/node/generateServiceWorker.js +0 -40
- package/lib/node/index.d.ts +0 -4
- package/lib/node/index.js +0 -20
- package/lib/node/pwaPlugin.d.ts +0 -17
- package/lib/node/pwaPlugin.js +0 -22
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vuepress/plugin-pwa",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.50-pre",
|
|
4
4
|
"description": "VuePress plugin - progressive web application",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vuepress-plugin",
|
|
@@ -18,19 +18,25 @@
|
|
|
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
|
-
"lib"
|
|
30
|
+
"./lib"
|
|
25
31
|
],
|
|
26
32
|
"dependencies": {
|
|
27
|
-
"@vuepress/client": "2.0.0-beta.
|
|
28
|
-
"@vuepress/core": "2.0.0-beta.
|
|
29
|
-
"@vuepress/utils": "2.0.0-beta.
|
|
33
|
+
"@vuepress/client": "2.0.0-beta.50-pre",
|
|
34
|
+
"@vuepress/core": "2.0.0-beta.50-pre",
|
|
35
|
+
"@vuepress/utils": "2.0.0-beta.50-pre",
|
|
30
36
|
"mitt": "^3.0.0",
|
|
31
37
|
"register-service-worker": "^1.7.2",
|
|
32
|
-
"vue": "^3.2.
|
|
33
|
-
"workbox-build": "^6.5.
|
|
38
|
+
"vue": "^3.2.37",
|
|
39
|
+
"workbox-build": "^6.5.4"
|
|
34
40
|
},
|
|
35
41
|
"publishConfig": {
|
|
36
42
|
"access": "public"
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Emitter } from 'mitt';
|
|
2
|
-
import type { InjectionKey } from 'vue';
|
|
3
|
-
export declare 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: () => PwaEvent;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { inject } from 'vue';
|
|
2
|
-
export const pwaEventSymbol = Symbol('pwaEvent');
|
|
3
|
-
export const usePwaEvent = () => {
|
|
4
|
-
const pwaEvent = inject(pwaEventSymbol);
|
|
5
|
-
if (!pwaEvent) {
|
|
6
|
-
throw new Error('usePwaEvent() is called without provider.');
|
|
7
|
-
}
|
|
8
|
-
return pwaEvent;
|
|
9
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Call `skipWaiting()` inside current waiting worker
|
|
3
|
-
*/
|
|
4
|
-
export const useSkipWaiting = (registration) => {
|
|
5
|
-
// get the waiting worker
|
|
6
|
-
const worker = registration.waiting;
|
|
7
|
-
// if there is no waiting worker, return directly
|
|
8
|
-
if (!worker)
|
|
9
|
-
return;
|
|
10
|
-
// post SKIP_WAITING message to the waiting worker
|
|
11
|
-
const channel = new MessageChannel();
|
|
12
|
-
worker.postMessage({ type: 'SKIP_WAITING' }, [channel.port2]);
|
|
13
|
-
};
|
package/lib/client/config.d.ts
DELETED
package/lib/client/config.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
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
|
-
});
|
package/lib/client/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './composables';
|
package/lib/client/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './composables';
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { App } from '@vuepress/core';
|
|
2
|
-
import type { GenerateSWOptions } from 'workbox-build';
|
|
3
|
-
export declare type GenerateSWConfig = Omit<GenerateSWOptions, 'swDest' | 'globDirectory'>;
|
|
4
|
-
export declare const generateServiceWorker: (app: App, serviceWorkerFilename: string, generateSWConfig: GenerateSWConfig) => Promise<void>;
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateServiceWorker = 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 generateServiceWorker = async (app, serviceWorkerFilename, generateSWConfig) => {
|
|
24
|
-
// lazy-load workbox-build
|
|
25
|
-
const { generateSW } = await Promise.resolve().then(() => require('workbox-build'));
|
|
26
|
-
const globDirectory = app.dir.dest();
|
|
27
|
-
const swDest = app.dir.dest(serviceWorkerFilename);
|
|
28
|
-
const { warnings } = await generateSW({
|
|
29
|
-
dontCacheBustURLsMatching: new RegExp(`\\.[0-9a-f]{8}\\.(${assetsExtensions.join('|')})$`),
|
|
30
|
-
globPatterns: [`**/*.{${assetsExtensions.join(',')}}`],
|
|
31
|
-
mode: app.env.isDebug ? 'development' : 'production',
|
|
32
|
-
sourcemap: app.env.isDebug,
|
|
33
|
-
...generateSWConfig,
|
|
34
|
-
// should not be override by user config
|
|
35
|
-
globDirectory,
|
|
36
|
-
swDest,
|
|
37
|
-
});
|
|
38
|
-
warnings.forEach((warning) => utils_1.logger.warn('[@vuepress/plugin-pwa]', warning));
|
|
39
|
-
};
|
|
40
|
-
exports.generateServiceWorker = generateServiceWorker;
|
package/lib/node/index.d.ts
DELETED
package/lib/node/index.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
const pwaPlugin_1 = require("./pwaPlugin");
|
|
18
|
-
__exportStar(require("./generateServiceWorker"), exports);
|
|
19
|
-
__exportStar(require("./pwaPlugin"), exports);
|
|
20
|
-
exports.default = pwaPlugin_1.pwaPlugin;
|
package/lib/node/pwaPlugin.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { Plugin } from '@vuepress/core';
|
|
2
|
-
import type { GenerateSWConfig } from './generateServiceWorker';
|
|
3
|
-
/**
|
|
4
|
-
* Options for @vuepress/plugin-pwa
|
|
5
|
-
*/
|
|
6
|
-
export interface PwaPluginOptions extends GenerateSWConfig {
|
|
7
|
-
/**
|
|
8
|
-
* Filename of the generated service worker file
|
|
9
|
-
*
|
|
10
|
-
* If you put it into a sub directory, the `scope` of service worker
|
|
11
|
-
* might be affected
|
|
12
|
-
*
|
|
13
|
-
* @default 'service-worker.js'
|
|
14
|
-
*/
|
|
15
|
-
serviceWorkerFilename?: string;
|
|
16
|
-
}
|
|
17
|
-
export declare const pwaPlugin: ({ serviceWorkerFilename, ...generateSWConfig }?: PwaPluginOptions) => Plugin;
|
package/lib/node/pwaPlugin.js
DELETED
|
@@ -1,22 +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 generateServiceWorker_1 = require("./generateServiceWorker");
|
|
6
|
-
const pwaPlugin = ({ serviceWorkerFilename = 'service-worker.js', ...generateSWConfig } = {}) => (app) => {
|
|
7
|
-
const plugin = {
|
|
8
|
-
name: '@vuepress/plugin-pwa',
|
|
9
|
-
};
|
|
10
|
-
if (app.env.isDev) {
|
|
11
|
-
return plugin;
|
|
12
|
-
}
|
|
13
|
-
return {
|
|
14
|
-
...plugin,
|
|
15
|
-
clientConfigFile: utils_1.path.resolve(__dirname, '../client/config.js'),
|
|
16
|
-
define: {
|
|
17
|
-
__PWA_SW_FILENAME__: serviceWorkerFilename,
|
|
18
|
-
},
|
|
19
|
-
onGenerated: (app) => (0, utils_1.withSpinner)('Generating service worker')(() => (0, generateServiceWorker_1.generateServiceWorker)(app, serviceWorkerFilename, generateSWConfig)),
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
exports.pwaPlugin = pwaPlugin;
|