@docusaurus/plugin-pwa 3.3.2 → 3.5.0
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.d.ts +1 -2
- package/lib/index.js +27 -27
- package/lib/options.d.ts +0 -1
- package/lib/options.js +1 -2
- package/lib/renderReloadPopup.d.ts +0 -1
- package/lib/theme/PwaReloadPopup/index.d.ts +0 -2
- package/package.json +10 -9
- package/src/index.ts +35 -34
package/lib/index.d.ts
CHANGED
|
@@ -4,8 +4,7 @@
|
|
|
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
|
-
/// <reference path="../src/plugin-pwa.d.ts" />
|
|
8
7
|
import type { LoadContext, Plugin } from '@docusaurus/types';
|
|
9
8
|
import type { PluginOptions } from '@docusaurus/plugin-pwa';
|
|
10
|
-
export default function pluginPWA(context: LoadContext, options: PluginOptions): Plugin<void
|
|
9
|
+
export default function pluginPWA(context: LoadContext, options: PluginOptions): Plugin<void> | null;
|
|
11
10
|
export { validateOptions } from './options';
|
package/lib/index.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.validateOptions = void 0;
|
|
10
|
+
exports.default = pluginPWA;
|
|
10
11
|
const tslib_1 = require("tslib");
|
|
11
12
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
13
|
const webpack_1 = tslib_1.__importDefault(require("webpack"));
|
|
@@ -14,9 +15,10 @@ const webpackbar_1 = tslib_1.__importDefault(require("webpackbar"));
|
|
|
14
15
|
const terser_webpack_plugin_1 = tslib_1.__importDefault(require("terser-webpack-plugin"));
|
|
15
16
|
const workbox_build_1 = require("workbox-build");
|
|
16
17
|
const utils_1 = require("@docusaurus/utils");
|
|
18
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
17
19
|
const utils_2 = require("@docusaurus/core/lib/webpack/utils");
|
|
18
20
|
const theme_translations_1 = require("@docusaurus/theme-translations");
|
|
19
|
-
const
|
|
21
|
+
const PluginName = 'docusaurus-plugin-pwa';
|
|
20
22
|
function getSWBabelLoader() {
|
|
21
23
|
return {
|
|
22
24
|
loader: 'babel-loader',
|
|
@@ -38,10 +40,17 @@ function getSWBabelLoader() {
|
|
|
38
40
|
};
|
|
39
41
|
}
|
|
40
42
|
function pluginPWA(context, options) {
|
|
43
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
if (context.siteConfig.future.experimental_router === 'hash') {
|
|
47
|
+
logger_1.default.warn(`${PluginName} does not support the Hash Router and will be disabled.`);
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
41
50
|
const { outDir, baseUrl, i18n: { currentLocale }, } = context;
|
|
42
51
|
const { debug, offlineModeActivationStrategies, injectManifestConfig, pwaHead, swCustom, swRegister, } = options;
|
|
43
52
|
return {
|
|
44
|
-
name:
|
|
53
|
+
name: PluginName,
|
|
45
54
|
getThemePath() {
|
|
46
55
|
return '../lib/theme';
|
|
47
56
|
},
|
|
@@ -49,7 +58,7 @@ function pluginPWA(context, options) {
|
|
|
49
58
|
return '../src/theme';
|
|
50
59
|
},
|
|
51
60
|
getClientModules() {
|
|
52
|
-
return
|
|
61
|
+
return swRegister ? [swRegister] : [];
|
|
53
62
|
},
|
|
54
63
|
getDefaultCodeTranslationMessages() {
|
|
55
64
|
return (0, theme_translations_1.readDefaultCodeTranslationMessages)({
|
|
@@ -58,9 +67,6 @@ function pluginPWA(context, options) {
|
|
|
58
67
|
});
|
|
59
68
|
},
|
|
60
69
|
configureWebpack(config) {
|
|
61
|
-
if (!isProd) {
|
|
62
|
-
return {};
|
|
63
|
-
}
|
|
64
70
|
return {
|
|
65
71
|
plugins: [
|
|
66
72
|
new webpack_1.default.EnvironmentPlugin({
|
|
@@ -73,30 +79,25 @@ function pluginPWA(context, options) {
|
|
|
73
79
|
},
|
|
74
80
|
injectHtmlTags() {
|
|
75
81
|
const headTags = [];
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
attributes,
|
|
91
|
-
});
|
|
82
|
+
pwaHead.forEach(({ tagName, ...attributes }) => {
|
|
83
|
+
['href', 'content'].forEach((attribute) => {
|
|
84
|
+
const attributeValue = attributes[attribute];
|
|
85
|
+
if (!attributeValue) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const attributePath = !!path_1.default.extname(attributeValue) && attributeValue;
|
|
89
|
+
if (attributePath && !attributePath.startsWith(baseUrl)) {
|
|
90
|
+
attributes[attribute] = (0, utils_1.normalizeUrl)([baseUrl, attributeValue]);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
return headTags.push({
|
|
94
|
+
tagName,
|
|
95
|
+
attributes,
|
|
92
96
|
});
|
|
93
|
-
}
|
|
97
|
+
});
|
|
94
98
|
return { headTags };
|
|
95
99
|
},
|
|
96
100
|
async postBuild(props) {
|
|
97
|
-
if (!isProd) {
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
101
|
const swSourceFileTest = /\.m?js$/;
|
|
101
102
|
const swWebpackConfig = {
|
|
102
103
|
entry: require.resolve('./sw.js'),
|
|
@@ -159,6 +160,5 @@ function pluginPWA(context, options) {
|
|
|
159
160
|
},
|
|
160
161
|
};
|
|
161
162
|
}
|
|
162
|
-
exports.default = pluginPWA;
|
|
163
163
|
var options_1 = require("./options");
|
|
164
164
|
Object.defineProperty(exports, "validateOptions", { enumerable: true, get: function () { return options_1.validateOptions; } });
|
package/lib/options.d.ts
CHANGED
|
@@ -4,7 +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
|
-
/// <reference path="../src/plugin-pwa.d.ts" />
|
|
8
7
|
import type { OptionValidationContext } from '@docusaurus/types';
|
|
9
8
|
import type { PluginOptions } from '@docusaurus/plugin-pwa';
|
|
10
9
|
export declare function validateOptions({ validate, options, }: OptionValidationContext<PluginOptions, PluginOptions>): PluginOptions;
|
package/lib/options.js
CHANGED
|
@@ -6,7 +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 =
|
|
9
|
+
exports.validateOptions = validateOptions;
|
|
10
10
|
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
11
11
|
const DEFAULT_OPTIONS = {
|
|
12
12
|
debug: false,
|
|
@@ -43,4 +43,3 @@ const optionsSchema = utils_validation_1.Joi.object({
|
|
|
43
43
|
function validateOptions({ validate, options, }) {
|
|
44
44
|
return validate(optionsSchema, options);
|
|
45
45
|
}
|
|
46
|
-
exports.validateOptions = validateOptions;
|
|
@@ -4,6 +4,5 @@
|
|
|
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
|
-
/// <reference path="../src/plugin-pwa.d.ts" />
|
|
8
7
|
import type { Props } from '@theme/PwaReloadPopup';
|
|
9
8
|
export declare function renderReloadPopup(props: Props): Promise<void>;
|
|
@@ -4,7 +4,5 @@
|
|
|
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
|
-
/// <reference path="../../../src/plugin-pwa.d.ts" />
|
|
8
|
-
/// <reference types="react" />
|
|
9
7
|
import type { Props } from '@theme/PwaReloadPopup';
|
|
10
8
|
export default function PwaReloadPopup({ onReload }: Props): JSX.Element | false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/plugin-pwa",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"description": "Docusaurus Plugin to add PWA support.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/plugin-pwa.d.ts",
|
|
@@ -22,12 +22,13 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@babel/core": "^7.23.3",
|
|
24
24
|
"@babel/preset-env": "^7.23.3",
|
|
25
|
-
"@docusaurus/core": "3.
|
|
26
|
-
"@docusaurus/
|
|
27
|
-
"@docusaurus/theme-
|
|
28
|
-
"@docusaurus/
|
|
29
|
-
"@docusaurus/
|
|
30
|
-
"@docusaurus/utils
|
|
25
|
+
"@docusaurus/core": "3.5.0",
|
|
26
|
+
"@docusaurus/logger": "3.5.0",
|
|
27
|
+
"@docusaurus/theme-common": "3.5.0",
|
|
28
|
+
"@docusaurus/theme-translations": "3.5.0",
|
|
29
|
+
"@docusaurus/types": "3.5.0",
|
|
30
|
+
"@docusaurus/utils": "3.5.0",
|
|
31
|
+
"@docusaurus/utils-validation": "3.5.0",
|
|
31
32
|
"babel-loader": "^9.1.3",
|
|
32
33
|
"clsx": "^2.0.0",
|
|
33
34
|
"core-js": "^3.31.1",
|
|
@@ -41,7 +42,7 @@
|
|
|
41
42
|
"workbox-window": "^7.0.0"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
44
|
-
"@docusaurus/module-type-aliases": "3.
|
|
45
|
+
"@docusaurus/module-type-aliases": "3.5.0",
|
|
45
46
|
"fs-extra": "^11.1.0"
|
|
46
47
|
},
|
|
47
48
|
"peerDependencies": {
|
|
@@ -51,5 +52,5 @@
|
|
|
51
52
|
"engines": {
|
|
52
53
|
"node": ">=18.0"
|
|
53
54
|
},
|
|
54
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "cb5829f3c34b26d798b869e38ee25073488140bd"
|
|
55
56
|
}
|
package/src/index.ts
CHANGED
|
@@ -11,12 +11,13 @@ import WebpackBar from 'webpackbar';
|
|
|
11
11
|
import Terser from 'terser-webpack-plugin';
|
|
12
12
|
import {injectManifest} from 'workbox-build';
|
|
13
13
|
import {normalizeUrl} from '@docusaurus/utils';
|
|
14
|
+
import logger from '@docusaurus/logger';
|
|
14
15
|
import {compile} from '@docusaurus/core/lib/webpack/utils';
|
|
15
16
|
import {readDefaultCodeTranslationMessages} from '@docusaurus/theme-translations';
|
|
16
17
|
import type {HtmlTags, LoadContext, Plugin} from '@docusaurus/types';
|
|
17
18
|
import type {PluginOptions} from '@docusaurus/plugin-pwa';
|
|
18
19
|
|
|
19
|
-
const
|
|
20
|
+
const PluginName = 'docusaurus-plugin-pwa';
|
|
20
21
|
|
|
21
22
|
function getSWBabelLoader() {
|
|
22
23
|
return {
|
|
@@ -42,7 +43,17 @@ function getSWBabelLoader() {
|
|
|
42
43
|
export default function pluginPWA(
|
|
43
44
|
context: LoadContext,
|
|
44
45
|
options: PluginOptions,
|
|
45
|
-
): Plugin<void> {
|
|
46
|
+
): Plugin<void> | null {
|
|
47
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
if (context.siteConfig.future.experimental_router === 'hash') {
|
|
51
|
+
logger.warn(
|
|
52
|
+
`${PluginName} does not support the Hash Router and will be disabled.`,
|
|
53
|
+
);
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
|
|
46
57
|
const {
|
|
47
58
|
outDir,
|
|
48
59
|
baseUrl,
|
|
@@ -58,7 +69,7 @@ export default function pluginPWA(
|
|
|
58
69
|
} = options;
|
|
59
70
|
|
|
60
71
|
return {
|
|
61
|
-
name:
|
|
72
|
+
name: PluginName,
|
|
62
73
|
|
|
63
74
|
getThemePath() {
|
|
64
75
|
return '../lib/theme';
|
|
@@ -68,7 +79,7 @@ export default function pluginPWA(
|
|
|
68
79
|
},
|
|
69
80
|
|
|
70
81
|
getClientModules() {
|
|
71
|
-
return
|
|
82
|
+
return swRegister ? [swRegister] : [];
|
|
72
83
|
},
|
|
73
84
|
|
|
74
85
|
getDefaultCodeTranslationMessages() {
|
|
@@ -79,10 +90,6 @@ export default function pluginPWA(
|
|
|
79
90
|
},
|
|
80
91
|
|
|
81
92
|
configureWebpack(config) {
|
|
82
|
-
if (!isProd) {
|
|
83
|
-
return {};
|
|
84
|
-
}
|
|
85
|
-
|
|
86
93
|
return {
|
|
87
94
|
plugins: [
|
|
88
95
|
new webpack.EnvironmentPlugin({
|
|
@@ -100,37 +107,31 @@ export default function pluginPWA(
|
|
|
100
107
|
|
|
101
108
|
injectHtmlTags() {
|
|
102
109
|
const headTags: HtmlTags = [];
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
return headTags.push({
|
|
121
|
-
tagName,
|
|
122
|
-
attributes,
|
|
123
|
-
});
|
|
110
|
+
pwaHead.forEach(({tagName, ...attributes}) => {
|
|
111
|
+
(['href', 'content'] as const).forEach((attribute) => {
|
|
112
|
+
const attributeValue = attributes[attribute];
|
|
113
|
+
|
|
114
|
+
if (!attributeValue) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const attributePath =
|
|
119
|
+
!!path.extname(attributeValue) && attributeValue;
|
|
120
|
+
|
|
121
|
+
if (attributePath && !attributePath.startsWith(baseUrl)) {
|
|
122
|
+
attributes[attribute] = normalizeUrl([baseUrl, attributeValue]);
|
|
123
|
+
}
|
|
124
124
|
});
|
|
125
|
-
|
|
125
|
+
|
|
126
|
+
return headTags.push({
|
|
127
|
+
tagName,
|
|
128
|
+
attributes,
|
|
129
|
+
});
|
|
130
|
+
});
|
|
126
131
|
return {headTags};
|
|
127
132
|
},
|
|
128
133
|
|
|
129
134
|
async postBuild(props) {
|
|
130
|
-
if (!isProd) {
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
135
|
const swSourceFileTest = /\.m?js$/;
|
|
135
136
|
|
|
136
137
|
const swWebpackConfig: Configuration = {
|