@docusaurus/plugin-pwa 3.4.0 → 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 +24 -30
- 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 -10
- package/src/index.ts +32 -42
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"));
|
|
@@ -18,7 +19,6 @@ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
|
18
19
|
const utils_2 = require("@docusaurus/core/lib/webpack/utils");
|
|
19
20
|
const theme_translations_1 = require("@docusaurus/theme-translations");
|
|
20
21
|
const PluginName = 'docusaurus-plugin-pwa';
|
|
21
|
-
const isProd = process.env.NODE_ENV === 'production';
|
|
22
22
|
function getSWBabelLoader() {
|
|
23
23
|
return {
|
|
24
24
|
loader: 'babel-loader',
|
|
@@ -40,12 +40,15 @@ function getSWBabelLoader() {
|
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
42
|
function pluginPWA(context, options) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
if (context.siteConfig.future.experimental_router === 'hash') {
|
|
46
47
|
logger_1.default.warn(`${PluginName} does not support the Hash Router and will be disabled.`);
|
|
47
|
-
return
|
|
48
|
+
return null;
|
|
48
49
|
}
|
|
50
|
+
const { outDir, baseUrl, i18n: { currentLocale }, } = context;
|
|
51
|
+
const { debug, offlineModeActivationStrategies, injectManifestConfig, pwaHead, swCustom, swRegister, } = options;
|
|
49
52
|
return {
|
|
50
53
|
name: PluginName,
|
|
51
54
|
getThemePath() {
|
|
@@ -55,7 +58,7 @@ function pluginPWA(context, options) {
|
|
|
55
58
|
return '../src/theme';
|
|
56
59
|
},
|
|
57
60
|
getClientModules() {
|
|
58
|
-
return
|
|
61
|
+
return swRegister ? [swRegister] : [];
|
|
59
62
|
},
|
|
60
63
|
getDefaultCodeTranslationMessages() {
|
|
61
64
|
return (0, theme_translations_1.readDefaultCodeTranslationMessages)({
|
|
@@ -64,9 +67,6 @@ function pluginPWA(context, options) {
|
|
|
64
67
|
});
|
|
65
68
|
},
|
|
66
69
|
configureWebpack(config) {
|
|
67
|
-
if (!isProd) {
|
|
68
|
-
return {};
|
|
69
|
-
}
|
|
70
70
|
return {
|
|
71
71
|
plugins: [
|
|
72
72
|
new webpack_1.default.EnvironmentPlugin({
|
|
@@ -79,30 +79,25 @@ function pluginPWA(context, options) {
|
|
|
79
79
|
},
|
|
80
80
|
injectHtmlTags() {
|
|
81
81
|
const headTags = [];
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
return headTags.push({
|
|
95
|
-
tagName,
|
|
96
|
-
attributes,
|
|
97
|
-
});
|
|
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
|
+
}
|
|
98
92
|
});
|
|
99
|
-
|
|
93
|
+
return headTags.push({
|
|
94
|
+
tagName,
|
|
95
|
+
attributes,
|
|
96
|
+
});
|
|
97
|
+
});
|
|
100
98
|
return { headTags };
|
|
101
99
|
},
|
|
102
100
|
async postBuild(props) {
|
|
103
|
-
if (!isProd) {
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
101
|
const swSourceFileTest = /\.m?js$/;
|
|
107
102
|
const swWebpackConfig = {
|
|
108
103
|
entry: require.resolve('./sw.js'),
|
|
@@ -165,6 +160,5 @@ function pluginPWA(context, options) {
|
|
|
165
160
|
},
|
|
166
161
|
};
|
|
167
162
|
}
|
|
168
|
-
exports.default = pluginPWA;
|
|
169
163
|
var options_1 = require("./options");
|
|
170
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,13 +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/logger": "3.
|
|
27
|
-
"@docusaurus/theme-common": "3.
|
|
28
|
-
"@docusaurus/theme-translations": "3.
|
|
29
|
-
"@docusaurus/types": "3.
|
|
30
|
-
"@docusaurus/utils": "3.
|
|
31
|
-
"@docusaurus/utils-validation": "3.
|
|
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",
|
|
32
32
|
"babel-loader": "^9.1.3",
|
|
33
33
|
"clsx": "^2.0.0",
|
|
34
34
|
"core-js": "^3.31.1",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"workbox-window": "^7.0.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@docusaurus/module-type-aliases": "3.
|
|
45
|
+
"@docusaurus/module-type-aliases": "3.5.0",
|
|
46
46
|
"fs-extra": "^11.1.0"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"engines": {
|
|
53
53
|
"node": ">=18.0"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "cb5829f3c34b26d798b869e38ee25073488140bd"
|
|
56
56
|
}
|
package/src/index.ts
CHANGED
|
@@ -19,8 +19,6 @@ import type {PluginOptions} from '@docusaurus/plugin-pwa';
|
|
|
19
19
|
|
|
20
20
|
const PluginName = 'docusaurus-plugin-pwa';
|
|
21
21
|
|
|
22
|
-
const isProd = process.env.NODE_ENV === 'production';
|
|
23
|
-
|
|
24
22
|
function getSWBabelLoader() {
|
|
25
23
|
return {
|
|
26
24
|
loader: 'babel-loader',
|
|
@@ -45,12 +43,21 @@ function getSWBabelLoader() {
|
|
|
45
43
|
export default function pluginPWA(
|
|
46
44
|
context: LoadContext,
|
|
47
45
|
options: PluginOptions,
|
|
48
|
-
): 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
|
+
|
|
49
57
|
const {
|
|
50
58
|
outDir,
|
|
51
59
|
baseUrl,
|
|
52
60
|
i18n: {currentLocale},
|
|
53
|
-
siteConfig,
|
|
54
61
|
} = context;
|
|
55
62
|
const {
|
|
56
63
|
debug,
|
|
@@ -61,13 +68,6 @@ export default function pluginPWA(
|
|
|
61
68
|
swRegister,
|
|
62
69
|
} = options;
|
|
63
70
|
|
|
64
|
-
if (siteConfig.future.experimental_router === 'hash') {
|
|
65
|
-
logger.warn(
|
|
66
|
-
`${PluginName} does not support the Hash Router and will be disabled.`,
|
|
67
|
-
);
|
|
68
|
-
return {name: PluginName};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
71
|
return {
|
|
72
72
|
name: PluginName,
|
|
73
73
|
|
|
@@ -79,7 +79,7 @@ export default function pluginPWA(
|
|
|
79
79
|
},
|
|
80
80
|
|
|
81
81
|
getClientModules() {
|
|
82
|
-
return
|
|
82
|
+
return swRegister ? [swRegister] : [];
|
|
83
83
|
},
|
|
84
84
|
|
|
85
85
|
getDefaultCodeTranslationMessages() {
|
|
@@ -90,10 +90,6 @@ export default function pluginPWA(
|
|
|
90
90
|
},
|
|
91
91
|
|
|
92
92
|
configureWebpack(config) {
|
|
93
|
-
if (!isProd) {
|
|
94
|
-
return {};
|
|
95
|
-
}
|
|
96
|
-
|
|
97
93
|
return {
|
|
98
94
|
plugins: [
|
|
99
95
|
new webpack.EnvironmentPlugin({
|
|
@@ -111,37 +107,31 @@ export default function pluginPWA(
|
|
|
111
107
|
|
|
112
108
|
injectHtmlTags() {
|
|
113
109
|
const headTags: HtmlTags = [];
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
attributes,
|
|
134
|
-
});
|
|
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
|
+
});
|
|
125
|
+
|
|
126
|
+
return headTags.push({
|
|
127
|
+
tagName,
|
|
128
|
+
attributes,
|
|
135
129
|
});
|
|
136
|
-
}
|
|
130
|
+
});
|
|
137
131
|
return {headTags};
|
|
138
132
|
},
|
|
139
133
|
|
|
140
134
|
async postBuild(props) {
|
|
141
|
-
if (!isProd) {
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
135
|
const swSourceFileTest = /\.m?js$/;
|
|
146
136
|
|
|
147
137
|
const swWebpackConfig: Configuration = {
|