@docusaurus/plugin-pwa 2.0.0-beta.17 → 2.0.0-beta.18
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 +6 -7
- package/lib/options.d.ts +2 -4
- package/lib/options.js +4 -6
- package/lib/registerSw.js +1 -1
- package/lib/sw.js +1 -1
- package/package.json +15 -15
- package/src/index.ts +6 -7
- package/src/options.ts +4 -9
- package/src/plugin-pwa.d.ts +76 -12
- package/src/registerSw.js +1 -1
- package/src/sw.js +1 -1
package/lib/index.js
CHANGED
|
@@ -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)({
|
|
@@ -100,7 +100,7 @@ function pluginPWA(context, options) {
|
|
|
100
100
|
}
|
|
101
101
|
const swSourceFileTest = /\.m?js$/;
|
|
102
102
|
const swWebpackConfig = {
|
|
103
|
-
entry:
|
|
103
|
+
entry: require.resolve('./sw.js'),
|
|
104
104
|
output: {
|
|
105
105
|
path: outDir,
|
|
106
106
|
filename: 'sw.js',
|
|
@@ -148,9 +148,8 @@ function pluginPWA(context, options) {
|
|
|
148
148
|
'**/*.{js,json,css,html}',
|
|
149
149
|
'**/*.{png,jpg,jpeg,gif,svg,ico}',
|
|
150
150
|
'**/*.{woff,woff2,eot,ttf,otf}',
|
|
151
|
-
//
|
|
152
|
-
|
|
153
|
-
...(workbox_build_1.injectManifest.globPatterns || []),
|
|
151
|
+
// @ts-expect-error: internal API?
|
|
152
|
+
...(workbox_build_1.injectManifest.globPatterns ?? []),
|
|
154
153
|
],
|
|
155
154
|
// those attributes are not overrideable
|
|
156
155
|
swDest,
|
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 = 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
|
@@ -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();
|
package/lib/sw.js
CHANGED
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.18",
|
|
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.
|
|
23
|
+
"@babel/core": "^7.17.8",
|
|
24
24
|
"@babel/preset-env": "^7.16.11",
|
|
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.
|
|
25
|
+
"@docusaurus/core": "2.0.0-beta.18",
|
|
26
|
+
"@docusaurus/theme-common": "2.0.0-beta.18",
|
|
27
|
+
"@docusaurus/theme-translations": "2.0.0-beta.18",
|
|
28
|
+
"@docusaurus/utils": "2.0.0-beta.18",
|
|
29
|
+
"@docusaurus/utils-validation": "2.0.0-beta.18",
|
|
30
|
+
"babel-loader": "^8.2.4",
|
|
31
31
|
"clsx": "^1.1.1",
|
|
32
|
-
"core-js": "^3.21.
|
|
32
|
+
"core-js": "^3.21.1",
|
|
33
33
|
"terser-webpack-plugin": "^5.3.1",
|
|
34
34
|
"tslib": "^2.3.1",
|
|
35
|
-
"webpack": "^5.
|
|
35
|
+
"webpack": "^5.70.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.2",
|
|
38
|
+
"workbox-precaching": "^6.5.2",
|
|
39
|
+
"workbox-window": "^6.5.2"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@docusaurus/module-type-aliases": "2.0.0-beta.
|
|
42
|
+
"@docusaurus/module-type-aliases": "2.0.0-beta.18",
|
|
43
43
|
"fs-extra": "^10.0.1"
|
|
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": "1a945d06993d53376e61bed2c942799fe07dc336"
|
|
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',
|
|
@@ -189,9 +189,8 @@ export default function pluginPWA(
|
|
|
189
189
|
'**/*.{js,json,css,html}',
|
|
190
190
|
'**/*.{png,jpg,jpeg,gif,svg,ico}',
|
|
191
191
|
'**/*.{woff,woff2,eot,ttf,otf}',
|
|
192
|
-
//
|
|
193
|
-
|
|
194
|
-
...(injectManifest.globPatterns || []),
|
|
192
|
+
// @ts-expect-error: internal API?
|
|
193
|
+
...(injectManifest.globPatterns ?? []),
|
|
195
194
|
],
|
|
196
195
|
// those attributes are not overrideable
|
|
197
196
|
swDest,
|
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,90 @@
|
|
|
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;
|
|
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
|
};
|
|
25
84
|
}
|
|
26
85
|
|
|
27
86
|
declare module '@theme/PwaReloadPopup' {
|
|
28
87
|
export interface Props {
|
|
88
|
+
/**
|
|
89
|
+
* The popup should call this callback when the `reload` button is clicked.
|
|
90
|
+
* This will tell the service worker to install the waiting service worker
|
|
91
|
+
* and reload the page.
|
|
92
|
+
*/
|
|
29
93
|
readonly onReload: () => void;
|
|
30
94
|
}
|
|
31
95
|
export default function PwaReloadPopup(props: Props): JSX.Element;
|
package/src/registerSw.js
CHANGED
|
@@ -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();
|