@docusaurus/plugin-pwa 2.0.0-beta.16 → 2.0.0-beta.19
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/index.js +15 -16
- package/lib/options.d.ts +2 -4
- package/lib/options.js +4 -6
- package/lib/registerSw.js +3 -3
- package/lib/sw.js +4 -3
- package/package.json +18 -18
- package/src/index.ts +10 -10
- package/src/options.ts +4 -9
- package/src/plugin-pwa.d.ts +78 -12
- package/src/registerSw.js +3 -3
- package/src/sw.js +4 -3
package/lib/index.js
CHANGED
|
@@ -10,11 +10,11 @@ exports.validateOptions = void 0;
|
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const utils_1 = require("@docusaurus/utils");
|
|
12
12
|
const utils_2 = require("@docusaurus/core/lib/webpack/utils");
|
|
13
|
-
const LogPlugin_1 =
|
|
13
|
+
const LogPlugin_1 = tslib_1.__importDefault(require("@docusaurus/core/lib/webpack/plugins/LogPlugin"));
|
|
14
14
|
const theme_translations_1 = require("@docusaurus/theme-translations");
|
|
15
|
-
const path_1 =
|
|
16
|
-
const webpack_1 =
|
|
17
|
-
const terser_webpack_plugin_1 =
|
|
15
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
16
|
+
const webpack_1 = tslib_1.__importDefault(require("webpack"));
|
|
17
|
+
const terser_webpack_plugin_1 = tslib_1.__importDefault(require("terser-webpack-plugin"));
|
|
18
18
|
const workbox_build_1 = require("workbox-build");
|
|
19
19
|
const isProd = process.env.NODE_ENV === 'production';
|
|
20
20
|
function getSWBabelLoader() {
|
|
@@ -43,13 +43,13 @@ function pluginPWA(context, options) {
|
|
|
43
43
|
return {
|
|
44
44
|
name: 'docusaurus-plugin-pwa',
|
|
45
45
|
getThemePath() {
|
|
46
|
-
return
|
|
46
|
+
return '../lib/theme';
|
|
47
47
|
},
|
|
48
48
|
getTypeScriptThemePath() {
|
|
49
|
-
return
|
|
49
|
+
return '../src/theme';
|
|
50
50
|
},
|
|
51
51
|
getClientModules() {
|
|
52
|
-
return isProd ? [swRegister] : [];
|
|
52
|
+
return isProd && swRegister ? [swRegister] : [];
|
|
53
53
|
},
|
|
54
54
|
getDefaultCodeTranslationMessages() {
|
|
55
55
|
return (0, theme_translations_1.readDefaultCodeTranslationMessages)({
|
|
@@ -58,7 +58,6 @@ function pluginPWA(context, options) {
|
|
|
58
58
|
});
|
|
59
59
|
},
|
|
60
60
|
configureWebpack(config) {
|
|
61
|
-
var _a;
|
|
62
61
|
if (!isProd) {
|
|
63
62
|
return {};
|
|
64
63
|
}
|
|
@@ -66,7 +65,7 @@ function pluginPWA(context, options) {
|
|
|
66
65
|
plugins: [
|
|
67
66
|
new webpack_1.default.EnvironmentPlugin({
|
|
68
67
|
PWA_DEBUG: debug,
|
|
69
|
-
PWA_SERVICE_WORKER_URL: path_1.default.posix.resolve(`${
|
|
68
|
+
PWA_SERVICE_WORKER_URL: path_1.default.posix.resolve(`${config.output?.publicPath || '/'}`, 'sw.js'),
|
|
70
69
|
PWA_OFFLINE_MODE_ACTIVATION_STRATEGIES: offlineModeActivationStrategies,
|
|
71
70
|
PWA_RELOAD_POPUP: reloadPopup,
|
|
72
71
|
}),
|
|
@@ -101,7 +100,7 @@ function pluginPWA(context, options) {
|
|
|
101
100
|
}
|
|
102
101
|
const swSourceFileTest = /\.m?js$/;
|
|
103
102
|
const swWebpackConfig = {
|
|
104
|
-
entry:
|
|
103
|
+
entry: require.resolve('./sw.js'),
|
|
105
104
|
output: {
|
|
106
105
|
path: outDir,
|
|
107
106
|
filename: 'sw.js',
|
|
@@ -113,7 +112,7 @@ function pluginPWA(context, options) {
|
|
|
113
112
|
optimization: {
|
|
114
113
|
splitChunks: false,
|
|
115
114
|
minimize: !debug,
|
|
116
|
-
//
|
|
115
|
+
// See https://developers.google.com/web/tools/workbox/guides/using-bundlers#webpack
|
|
117
116
|
minimizer: debug
|
|
118
117
|
? []
|
|
119
118
|
: [
|
|
@@ -124,7 +123,8 @@ function pluginPWA(context, options) {
|
|
|
124
123
|
},
|
|
125
124
|
plugins: [
|
|
126
125
|
new webpack_1.default.EnvironmentPlugin({
|
|
127
|
-
|
|
126
|
+
// Fallback value required with Webpack 5
|
|
127
|
+
PWA_SW_CUSTOM: swCustom || '',
|
|
128
128
|
}),
|
|
129
129
|
new LogPlugin_1.default({
|
|
130
130
|
name: 'Service Worker',
|
|
@@ -149,11 +149,10 @@ function pluginPWA(context, options) {
|
|
|
149
149
|
'**/*.{js,json,css,html}',
|
|
150
150
|
'**/*.{png,jpg,jpeg,gif,svg,ico}',
|
|
151
151
|
'**/*.{woff,woff2,eot,ttf,otf}',
|
|
152
|
-
//
|
|
153
|
-
|
|
154
|
-
...(workbox_build_1.injectManifest.globPatterns || []),
|
|
152
|
+
// @ts-expect-error: internal API?
|
|
153
|
+
...(workbox_build_1.injectManifest.globPatterns ?? []),
|
|
155
154
|
],
|
|
156
|
-
//
|
|
155
|
+
// Those attributes are not overrideable
|
|
157
156
|
swDest,
|
|
158
157
|
swSrc: swDest,
|
|
159
158
|
globDirectory: props.outDir,
|
package/lib/options.d.ts
CHANGED
|
@@ -4,8 +4,6 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
8
|
-
import type { ThemeConfig, ValidationResult, OptionValidationContext } from '@docusaurus/types';
|
|
7
|
+
import type { OptionValidationContext } from '@docusaurus/types';
|
|
9
8
|
import type { PluginOptions } from '@docusaurus/plugin-pwa';
|
|
10
|
-
export declare
|
|
11
|
-
export declare function validateOptions({ validate, options, }: OptionValidationContext<PluginOptions>): ValidationResult<ThemeConfig>;
|
|
9
|
+
export declare function validateOptions({ validate, options, }: OptionValidationContext<PluginOptions, PluginOptions>): PluginOptions;
|
package/lib/options.js
CHANGED
|
@@ -6,9 +6,7 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.validateOptions =
|
|
10
|
-
const tslib_1 = require("tslib");
|
|
11
|
-
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
9
|
+
exports.validateOptions = void 0;
|
|
12
10
|
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
13
11
|
const DEFAULT_OPTIONS = {
|
|
14
12
|
debug: false,
|
|
@@ -20,10 +18,10 @@ const DEFAULT_OPTIONS = {
|
|
|
20
18
|
injectManifestConfig: {},
|
|
21
19
|
pwaHead: [],
|
|
22
20
|
swCustom: undefined,
|
|
23
|
-
swRegister:
|
|
21
|
+
swRegister: './registerSw.js',
|
|
24
22
|
reloadPopup: '@theme/PwaReloadPopup',
|
|
25
23
|
};
|
|
26
|
-
|
|
24
|
+
const Schema = utils_validation_1.Joi.object({
|
|
27
25
|
debug: utils_validation_1.Joi.bool().default(DEFAULT_OPTIONS.debug),
|
|
28
26
|
offlineModeActivationStrategies: utils_validation_1.Joi.array()
|
|
29
27
|
.items(utils_validation_1.Joi.string()
|
|
@@ -43,6 +41,6 @@ exports.Schema = utils_validation_1.Joi.object({
|
|
|
43
41
|
.default(DEFAULT_OPTIONS.reloadPopup),
|
|
44
42
|
});
|
|
45
43
|
function validateOptions({ validate, options, }) {
|
|
46
|
-
return validate(
|
|
44
|
+
return validate(Schema, options);
|
|
47
45
|
}
|
|
48
46
|
exports.validateOptions = validateOptions;
|
package/lib/registerSw.js
CHANGED
|
@@ -16,7 +16,7 @@ const PWA_OFFLINE_MODE_ACTIVATION_STRATEGIES =
|
|
|
16
16
|
const PWA_DEBUG = process.env.PWA_DEBUG;
|
|
17
17
|
/* eslint-enable prefer-destructuring */
|
|
18
18
|
|
|
19
|
-
const debug = PWA_DEBUG; //
|
|
19
|
+
const debug = PWA_DEBUG; // Shortcut
|
|
20
20
|
|
|
21
21
|
const MAX_MOBILE_WIDTH = 940;
|
|
22
22
|
|
|
@@ -79,7 +79,7 @@ function isStandaloneDisplayMode() {
|
|
|
79
79
|
const OfflineModeActivationStrategiesImplementations = {
|
|
80
80
|
always: () => true,
|
|
81
81
|
mobile: () => window.innerWidth <= MAX_MOBILE_WIDTH,
|
|
82
|
-
saveData: () => !!
|
|
82
|
+
saveData: () => !!navigator.connection?.saveData,
|
|
83
83
|
appInstalled: async () => {
|
|
84
84
|
const installedEventFired = await isAppInstalledEventFired();
|
|
85
85
|
const installedRelatedApps = await isAppInstalledRelatedApps();
|
|
@@ -101,7 +101,7 @@ async function getActiveStrategies() {
|
|
|
101
101
|
return isActive ? strategyName : undefined;
|
|
102
102
|
}),
|
|
103
103
|
);
|
|
104
|
-
return activeStrategies.filter(Boolean);
|
|
104
|
+
return activeStrategies.filter(Boolean);
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
async function isOfflineModeEnabled() {
|
package/lib/sw.js
CHANGED
|
@@ -18,7 +18,7 @@ function parseSwParams() {
|
|
|
18
18
|
return params;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
//
|
|
21
|
+
// Doc advises against dynamic imports in SW
|
|
22
22
|
// https://developers.google.com/web/tools/workbox/guides/using-bundlers#code_splitting_and_dynamic_imports
|
|
23
23
|
// https://twitter.com/sebastienlorber/status/1280155204575518720
|
|
24
24
|
// but looks it's working fine as it's inlined by webpack, need to double check
|
|
@@ -73,7 +73,8 @@ function getPossibleURLs(url) {
|
|
|
73
73
|
// eslint-disable-next-line no-underscore-dangle
|
|
74
74
|
const precacheManifest = self.__WB_MANIFEST;
|
|
75
75
|
const controller = new PrecacheController({
|
|
76
|
-
|
|
76
|
+
// Safer to turn this true?
|
|
77
|
+
fallbackToNetwork: true,
|
|
77
78
|
});
|
|
78
79
|
|
|
79
80
|
if (params.offlineMode) {
|
|
@@ -137,7 +138,7 @@ function getPossibleURLs(url) {
|
|
|
137
138
|
});
|
|
138
139
|
}
|
|
139
140
|
|
|
140
|
-
const type = event.data
|
|
141
|
+
const type = event.data?.type;
|
|
141
142
|
|
|
142
143
|
if (type === 'SKIP_WAITING') {
|
|
143
144
|
self.skipWaiting();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/plugin-pwa",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.19",
|
|
4
4
|
"description": "Docusaurus Plugin to add PWA support.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/plugin-pwa.d.ts",
|
|
@@ -20,31 +20,31 @@
|
|
|
20
20
|
},
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@babel/core": "^7.17.
|
|
24
|
-
"@babel/preset-env": "^7.
|
|
25
|
-
"@docusaurus/core": "2.0.0-beta.
|
|
26
|
-
"@docusaurus/theme-common": "2.0.0-beta.
|
|
27
|
-
"@docusaurus/theme-translations": "2.0.0-beta.
|
|
28
|
-
"@docusaurus/utils": "2.0.0-beta.
|
|
29
|
-
"@docusaurus/utils-validation": "2.0.0-beta.
|
|
30
|
-
"babel-loader": "^8.2.
|
|
23
|
+
"@babel/core": "^7.17.10",
|
|
24
|
+
"@babel/preset-env": "^7.17.10",
|
|
25
|
+
"@docusaurus/core": "2.0.0-beta.19",
|
|
26
|
+
"@docusaurus/theme-common": "2.0.0-beta.19",
|
|
27
|
+
"@docusaurus/theme-translations": "2.0.0-beta.19",
|
|
28
|
+
"@docusaurus/utils": "2.0.0-beta.19",
|
|
29
|
+
"@docusaurus/utils-validation": "2.0.0-beta.19",
|
|
30
|
+
"babel-loader": "^8.2.5",
|
|
31
31
|
"clsx": "^1.1.1",
|
|
32
|
-
"core-js": "^3.
|
|
32
|
+
"core-js": "^3.22.3",
|
|
33
33
|
"terser-webpack-plugin": "^5.3.1",
|
|
34
|
-
"tslib": "^2.
|
|
35
|
-
"webpack": "^5.
|
|
34
|
+
"tslib": "^2.4.0",
|
|
35
|
+
"webpack": "^5.72.0",
|
|
36
36
|
"webpack-merge": "^5.8.0",
|
|
37
|
-
"workbox-build": "^6.5.
|
|
38
|
-
"workbox-precaching": "^6.5.
|
|
39
|
-
"workbox-window": "^6.5.
|
|
37
|
+
"workbox-build": "^6.5.3",
|
|
38
|
+
"workbox-precaching": "^6.5.3",
|
|
39
|
+
"workbox-window": "^6.5.3"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@docusaurus/module-type-aliases": "2.0.0-beta.
|
|
43
|
-
"fs-extra": "^10.0
|
|
42
|
+
"@docusaurus/module-type-aliases": "2.0.0-beta.19",
|
|
43
|
+
"fs-extra": "^10.1.0"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"react": "^16.8.4 || ^17.0.0",
|
|
47
47
|
"react-dom": "^16.8.4 || ^17.0.0"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "a71e60a49cce93c1006ef10c41ac03187f057102"
|
|
50
50
|
}
|
package/src/index.ts
CHANGED
|
@@ -64,14 +64,14 @@ export default function pluginPWA(
|
|
|
64
64
|
name: 'docusaurus-plugin-pwa',
|
|
65
65
|
|
|
66
66
|
getThemePath() {
|
|
67
|
-
return
|
|
67
|
+
return '../lib/theme';
|
|
68
68
|
},
|
|
69
69
|
getTypeScriptThemePath() {
|
|
70
|
-
return
|
|
70
|
+
return '../src/theme';
|
|
71
71
|
},
|
|
72
72
|
|
|
73
73
|
getClientModules() {
|
|
74
|
-
return isProd ? [swRegister] : [];
|
|
74
|
+
return isProd && swRegister ? [swRegister] : [];
|
|
75
75
|
},
|
|
76
76
|
|
|
77
77
|
getDefaultCodeTranslationMessages() {
|
|
@@ -138,7 +138,7 @@ export default function pluginPWA(
|
|
|
138
138
|
const swSourceFileTest = /\.m?js$/;
|
|
139
139
|
|
|
140
140
|
const swWebpackConfig: Configuration = {
|
|
141
|
-
entry:
|
|
141
|
+
entry: require.resolve('./sw.js'),
|
|
142
142
|
output: {
|
|
143
143
|
path: outDir,
|
|
144
144
|
filename: 'sw.js',
|
|
@@ -150,7 +150,7 @@ export default function pluginPWA(
|
|
|
150
150
|
optimization: {
|
|
151
151
|
splitChunks: false,
|
|
152
152
|
minimize: !debug,
|
|
153
|
-
//
|
|
153
|
+
// See https://developers.google.com/web/tools/workbox/guides/using-bundlers#webpack
|
|
154
154
|
minimizer: debug
|
|
155
155
|
? []
|
|
156
156
|
: [
|
|
@@ -161,7 +161,8 @@ export default function pluginPWA(
|
|
|
161
161
|
},
|
|
162
162
|
plugins: [
|
|
163
163
|
new webpack.EnvironmentPlugin({
|
|
164
|
-
|
|
164
|
+
// Fallback value required with Webpack 5
|
|
165
|
+
PWA_SW_CUSTOM: swCustom || '',
|
|
165
166
|
}),
|
|
166
167
|
new LogPlugin({
|
|
167
168
|
name: 'Service Worker',
|
|
@@ -189,11 +190,10 @@ export default function pluginPWA(
|
|
|
189
190
|
'**/*.{js,json,css,html}',
|
|
190
191
|
'**/*.{png,jpg,jpeg,gif,svg,ico}',
|
|
191
192
|
'**/*.{woff,woff2,eot,ttf,otf}',
|
|
192
|
-
//
|
|
193
|
-
|
|
194
|
-
...(injectManifest.globPatterns || []),
|
|
193
|
+
// @ts-expect-error: internal API?
|
|
194
|
+
...(injectManifest.globPatterns ?? []),
|
|
195
195
|
],
|
|
196
|
-
//
|
|
196
|
+
// Those attributes are not overrideable
|
|
197
197
|
swDest,
|
|
198
198
|
swSrc: swDest,
|
|
199
199
|
globDirectory: props.outDir,
|
package/src/options.ts
CHANGED
|
@@ -5,13 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import path from 'path';
|
|
9
8
|
import {Joi} from '@docusaurus/utils-validation';
|
|
10
|
-
import type {
|
|
11
|
-
ThemeConfig,
|
|
12
|
-
ValidationResult,
|
|
13
|
-
OptionValidationContext,
|
|
14
|
-
} from '@docusaurus/types';
|
|
9
|
+
import type {OptionValidationContext} from '@docusaurus/types';
|
|
15
10
|
import type {PluginOptions} from '@docusaurus/plugin-pwa';
|
|
16
11
|
|
|
17
12
|
const DEFAULT_OPTIONS = {
|
|
@@ -24,11 +19,11 @@ const DEFAULT_OPTIONS = {
|
|
|
24
19
|
injectManifestConfig: {},
|
|
25
20
|
pwaHead: [],
|
|
26
21
|
swCustom: undefined,
|
|
27
|
-
swRegister:
|
|
22
|
+
swRegister: './registerSw.js',
|
|
28
23
|
reloadPopup: '@theme/PwaReloadPopup',
|
|
29
24
|
};
|
|
30
25
|
|
|
31
|
-
|
|
26
|
+
const Schema = Joi.object({
|
|
32
27
|
debug: Joi.bool().default(DEFAULT_OPTIONS.debug),
|
|
33
28
|
offlineModeActivationStrategies: Joi.array()
|
|
34
29
|
.items(
|
|
@@ -62,6 +57,6 @@ export const Schema = Joi.object({
|
|
|
62
57
|
export function validateOptions({
|
|
63
58
|
validate,
|
|
64
59
|
options,
|
|
65
|
-
}: OptionValidationContext<PluginOptions>):
|
|
60
|
+
}: OptionValidationContext<PluginOptions, PluginOptions>): PluginOptions {
|
|
66
61
|
return validate(Schema, options);
|
|
67
62
|
}
|
package/src/plugin-pwa.d.ts
CHANGED
|
@@ -6,26 +6,92 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
declare module '@docusaurus/plugin-pwa' {
|
|
9
|
-
|
|
10
|
-
tagName: string;
|
|
11
|
-
href?: string;
|
|
12
|
-
content?: string;
|
|
13
|
-
[attributeName: string]: string | boolean;
|
|
14
|
-
};
|
|
9
|
+
import type {InjectManifestOptions} from 'workbox-build';
|
|
15
10
|
|
|
16
11
|
export type PluginOptions = {
|
|
12
|
+
/**
|
|
13
|
+
* Turn debug mode on:
|
|
14
|
+
*
|
|
15
|
+
* - Workbox logs
|
|
16
|
+
* - Additional Docusaurus logs
|
|
17
|
+
* - Unoptimized SW file output
|
|
18
|
+
* - Source maps
|
|
19
|
+
*/
|
|
17
20
|
debug?: boolean;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Strategies used to turn the offline mode on:
|
|
23
|
+
*
|
|
24
|
+
* - `appInstalled`: activates for users having installed the site as an app
|
|
25
|
+
* (not 100% reliable)
|
|
26
|
+
* - `standalone`: activates for users running the app as standalone (often
|
|
27
|
+
* the case once a PWA is installed)
|
|
28
|
+
* - `queryString`: activates if queryString contains `offlineMode=true`
|
|
29
|
+
* (convenient for PWA debugging)
|
|
30
|
+
* - `mobile`: activates for mobile users (width <= 940px)
|
|
31
|
+
* - `saveData`: activates for users with `navigator.connection.saveData ===
|
|
32
|
+
* true`
|
|
33
|
+
* - `always`: activates for all users
|
|
34
|
+
*/
|
|
35
|
+
offlineModeActivationStrategies: (
|
|
36
|
+
| 'appInstalled'
|
|
37
|
+
| 'queryString'
|
|
38
|
+
| 'standalone'
|
|
39
|
+
| 'mobile'
|
|
40
|
+
| 'saveData'
|
|
41
|
+
| 'always'
|
|
42
|
+
)[];
|
|
43
|
+
/**
|
|
44
|
+
* Workbox options to pass to `workbox.injectManifest()`. This gives you
|
|
45
|
+
* control over which assets will be precached, and be available offline.
|
|
46
|
+
* @see https://developers.google.com/web/tools/workbox/reference-docs/latest/module-workbox-build#.injectManifest
|
|
47
|
+
*/
|
|
48
|
+
injectManifestConfig: InjectManifestOptions;
|
|
49
|
+
/**
|
|
50
|
+
* Module path to reload popup component. This popup is rendered when a new
|
|
51
|
+
* service worker is waiting to be installed, and we suggest a reload to
|
|
52
|
+
* the user.
|
|
53
|
+
*
|
|
54
|
+
* Passing `false` will disable the popup, but this is not recommended:
|
|
55
|
+
* users won't have a way to get up-to-date content.
|
|
56
|
+
* @see {@link @theme/PwaReloadPopup}
|
|
57
|
+
*/
|
|
58
|
+
reloadPopup: string | false;
|
|
59
|
+
/**
|
|
60
|
+
* Array of objects containing `tagName` and key-value pairs for attributes
|
|
61
|
+
* to inject into the `<head>` tag. Technically you can inject any head tag
|
|
62
|
+
* through this, but it's ideally used for tags to make your site PWA-
|
|
63
|
+
* compliant.
|
|
64
|
+
*/
|
|
65
|
+
pwaHead: {
|
|
66
|
+
tagName: string;
|
|
67
|
+
href?: string;
|
|
68
|
+
content?: string;
|
|
69
|
+
[attributeName: string]: string | boolean | undefined;
|
|
70
|
+
}[];
|
|
71
|
+
/**
|
|
72
|
+
* Useful for additional Workbox rules. You can do whatever a service worker
|
|
73
|
+
* can do here, and use the full power of workbox libraries. The code is
|
|
74
|
+
* transpiled, so you can use modern ES6+ syntax here.
|
|
75
|
+
*/
|
|
76
|
+
swCustom?: string;
|
|
77
|
+
/**
|
|
78
|
+
* Adds an entry before the Docusaurus app so that registration can happen
|
|
79
|
+
* before the app runs. The default `registerSW.js` file is enough for
|
|
80
|
+
* simple registration. Passing `false` will disable registration entirely.
|
|
81
|
+
*/
|
|
82
|
+
swRegister: string | false;
|
|
24
83
|
};
|
|
84
|
+
|
|
85
|
+
export type Options = Partial<PluginOptions>;
|
|
25
86
|
}
|
|
26
87
|
|
|
27
88
|
declare module '@theme/PwaReloadPopup' {
|
|
28
89
|
export interface Props {
|
|
90
|
+
/**
|
|
91
|
+
* The popup should call this callback when the `reload` button is clicked.
|
|
92
|
+
* This will tell the service worker to install the waiting service worker
|
|
93
|
+
* and reload the page.
|
|
94
|
+
*/
|
|
29
95
|
readonly onReload: () => void;
|
|
30
96
|
}
|
|
31
97
|
export default function PwaReloadPopup(props: Props): JSX.Element;
|
package/src/registerSw.js
CHANGED
|
@@ -16,7 +16,7 @@ const PWA_OFFLINE_MODE_ACTIVATION_STRATEGIES =
|
|
|
16
16
|
const PWA_DEBUG = process.env.PWA_DEBUG;
|
|
17
17
|
/* eslint-enable prefer-destructuring */
|
|
18
18
|
|
|
19
|
-
const debug = PWA_DEBUG; //
|
|
19
|
+
const debug = PWA_DEBUG; // Shortcut
|
|
20
20
|
|
|
21
21
|
const MAX_MOBILE_WIDTH = 940;
|
|
22
22
|
|
|
@@ -79,7 +79,7 @@ function isStandaloneDisplayMode() {
|
|
|
79
79
|
const OfflineModeActivationStrategiesImplementations = {
|
|
80
80
|
always: () => true,
|
|
81
81
|
mobile: () => window.innerWidth <= MAX_MOBILE_WIDTH,
|
|
82
|
-
saveData: () => !!
|
|
82
|
+
saveData: () => !!navigator.connection?.saveData,
|
|
83
83
|
appInstalled: async () => {
|
|
84
84
|
const installedEventFired = await isAppInstalledEventFired();
|
|
85
85
|
const installedRelatedApps = await isAppInstalledRelatedApps();
|
|
@@ -101,7 +101,7 @@ async function getActiveStrategies() {
|
|
|
101
101
|
return isActive ? strategyName : undefined;
|
|
102
102
|
}),
|
|
103
103
|
);
|
|
104
|
-
return activeStrategies.filter(Boolean);
|
|
104
|
+
return activeStrategies.filter(Boolean);
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
async function isOfflineModeEnabled() {
|
package/src/sw.js
CHANGED
|
@@ -18,7 +18,7 @@ function parseSwParams() {
|
|
|
18
18
|
return params;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
//
|
|
21
|
+
// Doc advises against dynamic imports in SW
|
|
22
22
|
// https://developers.google.com/web/tools/workbox/guides/using-bundlers#code_splitting_and_dynamic_imports
|
|
23
23
|
// https://twitter.com/sebastienlorber/status/1280155204575518720
|
|
24
24
|
// but looks it's working fine as it's inlined by webpack, need to double check
|
|
@@ -73,7 +73,8 @@ function getPossibleURLs(url) {
|
|
|
73
73
|
// eslint-disable-next-line no-underscore-dangle
|
|
74
74
|
const precacheManifest = self.__WB_MANIFEST;
|
|
75
75
|
const controller = new PrecacheController({
|
|
76
|
-
|
|
76
|
+
// Safer to turn this true?
|
|
77
|
+
fallbackToNetwork: true,
|
|
77
78
|
});
|
|
78
79
|
|
|
79
80
|
if (params.offlineMode) {
|
|
@@ -137,7 +138,7 @@ function getPossibleURLs(url) {
|
|
|
137
138
|
});
|
|
138
139
|
}
|
|
139
140
|
|
|
140
|
-
const type = event.data
|
|
141
|
+
const type = event.data?.type;
|
|
141
142
|
|
|
142
143
|
if (type === 'SKIP_WAITING') {
|
|
143
144
|
self.skipWaiting();
|