@vuepress/plugin-pwa 2.0.0-beta.4 → 2.0.0-beta.42
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/{clientAppSetup.d.ts → client/clientAppSetup.d.ts} +0 -0
- package/lib/{clientAppSetup.js → client/clientAppSetup.js} +2 -2
- package/lib/{composables → client/composables}/index.d.ts +0 -0
- package/lib/{composables → client/composables}/index.js +0 -0
- package/lib/client/composables/usePwaEvent.d.ts +13 -0
- package/lib/{composables → client/composables}/usePwaEvent.js +3 -3
- package/lib/{composables → client/composables}/useSkipWaiting.d.ts +0 -0
- package/lib/{composables → client/composables}/useSkipWaiting.js +0 -0
- package/lib/client/index.d.ts +1 -0
- package/lib/client/index.js +1 -0
- package/lib/node/generateServiceWorker.d.ts +3 -0
- package/lib/node/generateServiceWorker.js +40 -0
- package/lib/node/index.d.ts +4 -0
- package/lib/node/index.js +20 -0
- package/lib/{index.d.ts → node/pwaPlugin.d.ts} +2 -4
- package/lib/node/pwaPlugin.js +22 -0
- package/package.json +15 -20
- package/CHANGELOG.md +0 -147
- package/lib/composables/usePwaEvent.d.ts +0 -22
- package/lib/index.js +0 -50
|
File without changes
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { defineClientAppSetup, withBase } from '@vuepress/client';
|
|
1
2
|
import mitt from 'mitt';
|
|
2
3
|
import { onMounted, provide } from 'vue';
|
|
3
|
-
import { defineClientAppSetup, withBase } from '@vuepress/client';
|
|
4
4
|
import { pwaEventSymbol } from './composables';
|
|
5
5
|
const swFilename = __PWA_SW_FILENAME__;
|
|
6
6
|
export default defineClientAppSetup(() => {
|
|
7
|
-
if (
|
|
7
|
+
if (__VUEPRESS_SSR__ || !swFilename)
|
|
8
8
|
return;
|
|
9
9
|
const log = (...args) => console.log('[@vuepress/plugin-pwa]', ...args);
|
|
10
10
|
// create event emitter and provide it
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,13 @@
|
|
|
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 +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
|
};
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './composables';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './composables';
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { App } from '@vuepress/core';
|
|
2
|
+
import type { generateSW as GenerateSWFunc } from 'workbox-build';
|
|
3
|
+
export declare const generateServiceWorker: (app: App, serviceWorkerFilename: string, generateSWConfig: Partial<Parameters<typeof GenerateSWFunc>[0]>) => Promise<void>;
|
|
@@ -0,0 +1,40 @@
|
|
|
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 } = 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;
|
|
@@ -0,0 +1,20 @@
|
|
|
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;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type { Plugin } from '@vuepress/core';
|
|
2
|
-
import type { GenerateSWConfig } from 'workbox-build';
|
|
3
2
|
/**
|
|
4
3
|
* Options for @vuepress/plugin-pwa
|
|
5
4
|
*/
|
|
6
|
-
export interface PwaPluginOptions extends Omit<
|
|
5
|
+
export interface PwaPluginOptions extends Omit<any, 'swDest' | 'globDirectory'> {
|
|
7
6
|
/**
|
|
8
7
|
* Filename of the generated service worker file
|
|
9
8
|
*
|
|
@@ -14,5 +13,4 @@ export interface PwaPluginOptions extends Omit<GenerateSWConfig, 'swDest' | 'glo
|
|
|
14
13
|
*/
|
|
15
14
|
serviceWorkerFilename?: string;
|
|
16
15
|
}
|
|
17
|
-
export declare const pwaPlugin: Plugin
|
|
18
|
-
export default pwaPlugin;
|
|
16
|
+
export declare const pwaPlugin: ({ serviceWorkerFilename, ...generateSWConfig }: PwaPluginOptions) => Plugin;
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
clientAppSetupFiles: utils_1.path.resolve(__dirname, '../client/clientAppSetup.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;
|
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.42",
|
|
4
4
|
"description": "VuePress plugin - progressive web application",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vuepress-plugin",
|
|
@@ -18,30 +18,25 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"author": "meteorlxy",
|
|
21
|
-
"main": "lib/index.js",
|
|
22
|
-
"types": "lib/index.d.ts",
|
|
21
|
+
"main": "lib/node/index.js",
|
|
22
|
+
"types": "lib/node/index.d.ts",
|
|
23
23
|
"files": [
|
|
24
|
-
"lib"
|
|
25
|
-
"styles"
|
|
24
|
+
"lib"
|
|
26
25
|
],
|
|
27
|
-
"scripts": {
|
|
28
|
-
"build": "tsc -b tsconfig.build.json",
|
|
29
|
-
"clean": "rimraf lib *.tsbuildinfo"
|
|
30
|
-
},
|
|
31
26
|
"dependencies": {
|
|
32
|
-
"@vuepress/client": "2.0.0-beta.
|
|
33
|
-
"@vuepress/core": "2.0.0-beta.
|
|
34
|
-
"@vuepress/utils": "2.0.0-beta.
|
|
35
|
-
"mitt": "^
|
|
27
|
+
"@vuepress/client": "2.0.0-beta.42",
|
|
28
|
+
"@vuepress/core": "2.0.0-beta.42",
|
|
29
|
+
"@vuepress/utils": "2.0.0-beta.42",
|
|
30
|
+
"mitt": "^3.0.0",
|
|
36
31
|
"register-service-worker": "^1.7.2",
|
|
37
|
-
"vue": "^3.
|
|
38
|
-
"workbox-build": "^6.
|
|
39
|
-
},
|
|
40
|
-
"devDependencies": {
|
|
41
|
-
"@types/workbox-build": "^5.0.0"
|
|
32
|
+
"vue": "^3.2.33",
|
|
33
|
+
"workbox-build": "^6.5.2"
|
|
42
34
|
},
|
|
43
35
|
"publishConfig": {
|
|
44
36
|
"access": "public"
|
|
45
37
|
},
|
|
46
|
-
"
|
|
47
|
-
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsc -b tsconfig.build.json",
|
|
40
|
+
"clean": "rimraf lib *.tsbuildinfo"
|
|
41
|
+
}
|
|
42
|
+
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,147 +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.4](https://github.com/vuepress/vuepress-next/compare/v2.0.0-beta.3...v2.0.0-beta.4) (2021-03-20)
|
|
7
|
-
|
|
8
|
-
**Note:** Version bump only for package @vuepress/plugin-pwa
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
# [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)
|
|
15
|
-
|
|
16
|
-
**Note:** Version bump only for package @vuepress/plugin-pwa
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
# [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)
|
|
23
|
-
|
|
24
|
-
**Note:** Version bump only for package @vuepress/plugin-pwa
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
# [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)
|
|
31
|
-
|
|
32
|
-
**Note:** Version bump only for package @vuepress/plugin-pwa
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
# [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)
|
|
39
|
-
|
|
40
|
-
**Note:** Version bump only for package @vuepress/plugin-pwa
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
# [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)
|
|
47
|
-
|
|
48
|
-
**Note:** Version bump only for package @vuepress/plugin-pwa
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
# [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)
|
|
55
|
-
|
|
56
|
-
**Note:** Version bump only for package @vuepress/plugin-pwa
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
# [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)
|
|
63
|
-
|
|
64
|
-
**Note:** Version bump only for package @vuepress/plugin-pwa
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
# [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)
|
|
71
|
-
|
|
72
|
-
**Note:** Version bump only for package @vuepress/plugin-pwa
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
# [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)
|
|
79
|
-
|
|
80
|
-
**Note:** Version bump only for package @vuepress/plugin-pwa
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
# [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)
|
|
87
|
-
|
|
88
|
-
**Note:** Version bump only for package @vuepress/plugin-pwa
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
# [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)
|
|
95
|
-
|
|
96
|
-
**Note:** Version bump only for package @vuepress/plugin-pwa
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
# [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)
|
|
103
|
-
|
|
104
|
-
**Note:** Version bump only for package @vuepress/plugin-pwa
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
# [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)
|
|
111
|
-
|
|
112
|
-
**Note:** Version bump only for package @vuepress/plugin-pwa
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
# [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)
|
|
119
|
-
|
|
120
|
-
**Note:** Version bump only for package @vuepress/plugin-pwa
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
# [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)
|
|
127
|
-
|
|
128
|
-
**Note:** Version bump only for package @vuepress/plugin-pwa
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
# [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)
|
|
135
|
-
|
|
136
|
-
**Note:** Version bump only for package @vuepress/plugin-pwa
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
# [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)
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
### Features
|
|
146
|
-
|
|
147
|
-
* **plugin-pwa:** migrate pwa plugin ([aa54fd6](https://github.com/vuepress/vuepress-next/commit/aa54fd65aa77b32b97de0a38359f1ad07f96f566))
|
|
@@ -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;
|