@docusaurus/plugin-pwa 0.0.0-5988 → 0.0.0-5993

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 CHANGED
@@ -6,5 +6,5 @@
6
6
  */
7
7
  import type { LoadContext, Plugin } from '@docusaurus/types';
8
8
  import type { PluginOptions } from '@docusaurus/plugin-pwa';
9
- export default function pluginPWA(context: LoadContext, options: PluginOptions): Plugin<void>;
9
+ export default function pluginPWA(context: LoadContext, options: PluginOptions): Plugin<void> | null;
10
10
  export { validateOptions } from './options';
package/lib/index.js CHANGED
@@ -19,7 +19,6 @@ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
19
19
  const utils_2 = require("@docusaurus/core/lib/webpack/utils");
20
20
  const theme_translations_1 = require("@docusaurus/theme-translations");
21
21
  const PluginName = 'docusaurus-plugin-pwa';
22
- const isProd = process.env.NODE_ENV === 'production';
23
22
  function getSWBabelLoader() {
24
23
  return {
25
24
  loader: 'babel-loader',
@@ -41,12 +40,15 @@ function getSWBabelLoader() {
41
40
  };
42
41
  }
43
42
  function pluginPWA(context, options) {
44
- const { outDir, baseUrl, i18n: { currentLocale }, siteConfig, } = context;
45
- const { debug, offlineModeActivationStrategies, injectManifestConfig, pwaHead, swCustom, swRegister, } = options;
46
- if (siteConfig.future.experimental_router === 'hash') {
43
+ if (process.env.NODE_ENV !== 'production') {
44
+ return null;
45
+ }
46
+ if (context.siteConfig.future.experimental_router === 'hash') {
47
47
  logger_1.default.warn(`${PluginName} does not support the Hash Router and will be disabled.`);
48
- return { name: PluginName };
48
+ return null;
49
49
  }
50
+ const { outDir, baseUrl, i18n: { currentLocale }, } = context;
51
+ const { debug, offlineModeActivationStrategies, injectManifestConfig, pwaHead, swCustom, swRegister, } = options;
50
52
  return {
51
53
  name: PluginName,
52
54
  getThemePath() {
@@ -56,7 +58,7 @@ function pluginPWA(context, options) {
56
58
  return '../src/theme';
57
59
  },
58
60
  getClientModules() {
59
- return isProd && swRegister ? [swRegister] : [];
61
+ return swRegister ? [swRegister] : [];
60
62
  },
61
63
  getDefaultCodeTranslationMessages() {
62
64
  return (0, theme_translations_1.readDefaultCodeTranslationMessages)({
@@ -65,9 +67,6 @@ function pluginPWA(context, options) {
65
67
  });
66
68
  },
67
69
  configureWebpack(config) {
68
- if (!isProd) {
69
- return {};
70
- }
71
70
  return {
72
71
  plugins: [
73
72
  new webpack_1.default.EnvironmentPlugin({
@@ -80,30 +79,25 @@ function pluginPWA(context, options) {
80
79
  },
81
80
  injectHtmlTags() {
82
81
  const headTags = [];
83
- if (isProd) {
84
- pwaHead.forEach(({ tagName, ...attributes }) => {
85
- ['href', 'content'].forEach((attribute) => {
86
- const attributeValue = attributes[attribute];
87
- if (!attributeValue) {
88
- return;
89
- }
90
- const attributePath = !!path_1.default.extname(attributeValue) && attributeValue;
91
- if (attributePath && !attributePath.startsWith(baseUrl)) {
92
- attributes[attribute] = (0, utils_1.normalizeUrl)([baseUrl, attributeValue]);
93
- }
94
- });
95
- return headTags.push({
96
- tagName,
97
- attributes,
98
- });
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
+ }
99
92
  });
100
- }
93
+ return headTags.push({
94
+ tagName,
95
+ attributes,
96
+ });
97
+ });
101
98
  return { headTags };
102
99
  },
103
100
  async postBuild(props) {
104
- if (!isProd) {
105
- return;
106
- }
107
101
  const swSourceFileTest = /\.m?js$/;
108
102
  const swWebpackConfig = {
109
103
  entry: require.resolve('./sw.js'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-pwa",
3
- "version": "0.0.0-5988",
3
+ "version": "0.0.0-5993",
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": "0.0.0-5988",
26
- "@docusaurus/logger": "0.0.0-5988",
27
- "@docusaurus/theme-common": "0.0.0-5988",
28
- "@docusaurus/theme-translations": "0.0.0-5988",
29
- "@docusaurus/types": "0.0.0-5988",
30
- "@docusaurus/utils": "0.0.0-5988",
31
- "@docusaurus/utils-validation": "0.0.0-5988",
25
+ "@docusaurus/core": "0.0.0-5993",
26
+ "@docusaurus/logger": "0.0.0-5993",
27
+ "@docusaurus/theme-common": "0.0.0-5993",
28
+ "@docusaurus/theme-translations": "0.0.0-5993",
29
+ "@docusaurus/types": "0.0.0-5993",
30
+ "@docusaurus/utils": "0.0.0-5993",
31
+ "@docusaurus/utils-validation": "0.0.0-5993",
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": "0.0.0-5988",
45
+ "@docusaurus/module-type-aliases": "0.0.0-5993",
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": "d0fdafd91649c846567d686ec00d3ff6ae494556"
55
+ "gitHead": "0ad0160fc910803276cb4b5fe34254b7ec372bd4"
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 isProd && swRegister ? [swRegister] : [];
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
- if (isProd) {
115
- pwaHead.forEach(({tagName, ...attributes}) => {
116
- (['href', 'content'] as const).forEach((attribute) => {
117
- const attributeValue = attributes[attribute];
118
-
119
- if (!attributeValue) {
120
- return;
121
- }
122
-
123
- const attributePath =
124
- !!path.extname(attributeValue) && attributeValue;
125
-
126
- if (attributePath && !attributePath.startsWith(baseUrl)) {
127
- attributes[attribute] = normalizeUrl([baseUrl, attributeValue]);
128
- }
129
- });
130
-
131
- return headTags.push({
132
- tagName,
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 = {