@docusaurus/plugin-pwa 3.5.2 → 3.6.0-canary-6134

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 CHANGED
@@ -10,13 +10,10 @@ exports.validateOptions = void 0;
10
10
  exports.default = pluginPWA;
11
11
  const tslib_1 = require("tslib");
12
12
  const path_1 = tslib_1.__importDefault(require("path"));
13
- const webpack_1 = tslib_1.__importDefault(require("webpack"));
14
- const webpackbar_1 = tslib_1.__importDefault(require("webpackbar"));
15
- const terser_webpack_plugin_1 = tslib_1.__importDefault(require("terser-webpack-plugin"));
13
+ const bundler_1 = require("@docusaurus/bundler");
16
14
  const workbox_build_1 = require("workbox-build");
17
15
  const utils_1 = require("@docusaurus/utils");
18
16
  const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
19
- const utils_2 = require("@docusaurus/core/lib/webpack/utils");
20
17
  const theme_translations_1 = require("@docusaurus/theme-translations");
21
18
  const PluginName = 'docusaurus-plugin-pwa';
22
19
  function getSWBabelLoader() {
@@ -31,7 +28,7 @@ function getSWBabelLoader() {
31
28
  {
32
29
  useBuiltIns: 'entry',
33
30
  corejs: '3',
34
- // See https://twitter.com/jeffposnick/status/1280223070876315649
31
+ // See https://x.com/jeffposnick/status/1280223070876315649
35
32
  targets: 'chrome >= 56',
36
33
  },
37
34
  ],
@@ -66,10 +63,10 @@ function pluginPWA(context, options) {
66
63
  name: 'plugin-pwa',
67
64
  });
68
65
  },
69
- configureWebpack(config) {
66
+ configureWebpack(config, isServer, { currentBundler }) {
70
67
  return {
71
68
  plugins: [
72
- new webpack_1.default.EnvironmentPlugin({
69
+ new currentBundler.instance.EnvironmentPlugin({
73
70
  PWA_DEBUG: debug,
74
71
  PWA_SERVICE_WORKER_URL: path_1.default.posix.resolve(`${config.output?.publicPath || '/'}`, 'sw.js'),
75
72
  PWA_OFFLINE_MODE_ACTIVATION_STRATEGIES: offlineModeActivationStrategies,
@@ -99,6 +96,9 @@ function pluginPWA(context, options) {
99
96
  },
100
97
  async postBuild(props) {
101
98
  const swSourceFileTest = /\.m?js$/;
99
+ const ProgressBarPlugin = await (0, bundler_1.getProgressBarPlugin)({
100
+ currentBundler: props.currentBundler,
101
+ });
102
102
  const swWebpackConfig = {
103
103
  entry: require.resolve('./sw.js'),
104
104
  output: {
@@ -115,18 +115,17 @@ function pluginPWA(context, options) {
115
115
  // See https://developers.google.com/web/tools/workbox/guides/using-bundlers#webpack
116
116
  minimizer: debug
117
117
  ? []
118
- : [
119
- new terser_webpack_plugin_1.default({
120
- test: swSourceFileTest,
121
- }),
122
- ],
118
+ : await (0, bundler_1.getMinimizers)({
119
+ faster: props.siteConfig.future.experimental_faster,
120
+ currentBundler: props.currentBundler,
121
+ }),
123
122
  },
124
123
  plugins: [
125
- new webpack_1.default.EnvironmentPlugin({
124
+ new props.currentBundler.instance.EnvironmentPlugin({
126
125
  // Fallback value required with Webpack 5
127
126
  PWA_SW_CUSTOM: swCustom ?? '',
128
127
  }),
129
- new webpackbar_1.default({
128
+ new ProgressBarPlugin({
130
129
  name: 'Service Worker',
131
130
  color: 'red',
132
131
  }),
@@ -141,7 +140,10 @@ function pluginPWA(context, options) {
141
140
  ],
142
141
  },
143
142
  };
144
- await (0, utils_2.compile)([swWebpackConfig]);
143
+ await (0, bundler_1.compile)({
144
+ configs: [swWebpackConfig],
145
+ currentBundler: props.currentBundler,
146
+ });
145
147
  const swDest = path_1.default.resolve(props.outDir, 'sw.js');
146
148
  await (0, workbox_build_1.injectManifest)({
147
149
  ...injectManifestConfig,
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import React from 'react';
8
- import ReactDOM from 'react-dom';
8
+ import { createRoot } from 'react-dom/client';
9
9
  const POPUP_CONTAINER_ID = 'pwa-popup-container';
10
10
  const getContainer = () => document.getElementById(POPUP_CONTAINER_ID);
11
11
  const createContainer = () => {
@@ -17,6 +17,7 @@ const createContainer = () => {
17
17
  export function renderReloadPopup(props) {
18
18
  const container = getContainer() ?? createContainer();
19
19
  return import('@theme/PwaReloadPopup').then(({ default: ReloadPopup }) => {
20
- ReactDOM.render(<ReloadPopup {...props}/>, container);
20
+ const root = createRoot(container);
21
+ root.render(<ReloadPopup {...props}/>);
21
22
  });
22
23
  }
package/lib/sw.js CHANGED
@@ -15,7 +15,7 @@ function parseSwParams() {
15
15
  }
16
16
  // Doc advises against dynamic imports in SW
17
17
  // https://developers.google.com/web/tools/workbox/guides/using-bundlers#code_splitting_and_dynamic_imports
18
- // https://twitter.com/sebastienlorber/status/1280155204575518720
18
+ // https://x.com/sebastienlorber/status/1280155204575518720
19
19
  // but looks it's working fine as it's inlined by webpack, need to double check
20
20
  async function runSWCustomCode(params) {
21
21
  if (process.env.PWA_SW_CUSTOM) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-pwa",
3
- "version": "3.5.2",
3
+ "version": "3.6.0-canary-6134",
4
4
  "description": "Docusaurus Plugin to add PWA support.",
5
5
  "main": "lib/index.js",
6
6
  "types": "src/plugin-pwa.d.ts",
@@ -20,29 +20,28 @@
20
20
  },
21
21
  "license": "MIT",
22
22
  "dependencies": {
23
- "@babel/core": "^7.23.3",
24
- "@babel/preset-env": "^7.23.3",
25
- "@docusaurus/core": "3.5.2",
26
- "@docusaurus/logger": "3.5.2",
27
- "@docusaurus/theme-common": "3.5.2",
28
- "@docusaurus/theme-translations": "3.5.2",
29
- "@docusaurus/types": "3.5.2",
30
- "@docusaurus/utils": "3.5.2",
31
- "@docusaurus/utils-validation": "3.5.2",
32
- "babel-loader": "^9.1.3",
23
+ "@babel/core": "^7.25.9",
24
+ "@babel/preset-env": "^7.25.9",
25
+ "@docusaurus/bundler": "3.6.0-canary-6134",
26
+ "@docusaurus/core": "3.6.0-canary-6134",
27
+ "@docusaurus/logger": "3.6.0-canary-6134",
28
+ "@docusaurus/theme-common": "3.6.0-canary-6134",
29
+ "@docusaurus/theme-translations": "3.6.0-canary-6134",
30
+ "@docusaurus/types": "3.6.0-canary-6134",
31
+ "@docusaurus/utils": "3.6.0-canary-6134",
32
+ "@docusaurus/utils-validation": "3.6.0-canary-6134",
33
+ "babel-loader": "^9.2.1",
33
34
  "clsx": "^2.0.0",
34
35
  "core-js": "^3.31.1",
35
- "terser-webpack-plugin": "^5.3.9",
36
36
  "tslib": "^2.6.0",
37
- "webpack": "^5.88.1",
37
+ "webpack": "^5.95.0",
38
38
  "webpack-merge": "^5.9.0",
39
- "webpackbar": "^5.0.2",
40
39
  "workbox-build": "^7.0.0",
41
40
  "workbox-precaching": "^7.0.0",
42
41
  "workbox-window": "^7.0.0"
43
42
  },
44
43
  "devDependencies": {
45
- "@docusaurus/module-type-aliases": "3.5.2",
44
+ "@docusaurus/module-type-aliases": "3.6.0-canary-6134",
46
45
  "fs-extra": "^11.1.0"
47
46
  },
48
47
  "peerDependencies": {
@@ -52,5 +51,5 @@
52
51
  "engines": {
53
52
  "node": ">=18.0"
54
53
  },
55
- "gitHead": "eeec303dd773774ed5a023884800da0b061f6942"
54
+ "gitHead": "706c96c3bdd92c7d3ac61447ec49e4bfa6d0526b"
56
55
  }
package/src/index.ts CHANGED
@@ -6,13 +6,15 @@
6
6
  */
7
7
 
8
8
  import path from 'path';
9
- import webpack, {type Configuration} from 'webpack';
10
- import WebpackBar from 'webpackbar';
11
- import Terser from 'terser-webpack-plugin';
9
+ import {type Configuration} from 'webpack';
10
+ import {
11
+ compile,
12
+ getProgressBarPlugin,
13
+ getMinimizers,
14
+ } from '@docusaurus/bundler';
12
15
  import {injectManifest} from 'workbox-build';
13
16
  import {normalizeUrl} from '@docusaurus/utils';
14
17
  import logger from '@docusaurus/logger';
15
- import {compile} from '@docusaurus/core/lib/webpack/utils';
16
18
  import {readDefaultCodeTranslationMessages} from '@docusaurus/theme-translations';
17
19
  import type {HtmlTags, LoadContext, Plugin} from '@docusaurus/types';
18
20
  import type {PluginOptions} from '@docusaurus/plugin-pwa';
@@ -31,7 +33,7 @@ function getSWBabelLoader() {
31
33
  {
32
34
  useBuiltIns: 'entry',
33
35
  corejs: '3',
34
- // See https://twitter.com/jeffposnick/status/1280223070876315649
36
+ // See https://x.com/jeffposnick/status/1280223070876315649
35
37
  targets: 'chrome >= 56',
36
38
  },
37
39
  ],
@@ -89,10 +91,10 @@ export default function pluginPWA(
89
91
  });
90
92
  },
91
93
 
92
- configureWebpack(config) {
94
+ configureWebpack(config, isServer, {currentBundler}) {
93
95
  return {
94
96
  plugins: [
95
- new webpack.EnvironmentPlugin({
97
+ new currentBundler.instance.EnvironmentPlugin({
96
98
  PWA_DEBUG: debug,
97
99
  PWA_SERVICE_WORKER_URL: path.posix.resolve(
98
100
  `${(config.output?.publicPath as string) || '/'}`,
@@ -134,6 +136,10 @@ export default function pluginPWA(
134
136
  async postBuild(props) {
135
137
  const swSourceFileTest = /\.m?js$/;
136
138
 
139
+ const ProgressBarPlugin = await getProgressBarPlugin({
140
+ currentBundler: props.currentBundler,
141
+ });
142
+
137
143
  const swWebpackConfig: Configuration = {
138
144
  entry: require.resolve('./sw.js'),
139
145
  output: {
@@ -150,18 +156,17 @@ export default function pluginPWA(
150
156
  // See https://developers.google.com/web/tools/workbox/guides/using-bundlers#webpack
151
157
  minimizer: debug
152
158
  ? []
153
- : [
154
- new Terser({
155
- test: swSourceFileTest,
156
- }),
157
- ],
159
+ : await getMinimizers({
160
+ faster: props.siteConfig.future.experimental_faster,
161
+ currentBundler: props.currentBundler,
162
+ }),
158
163
  },
159
164
  plugins: [
160
- new webpack.EnvironmentPlugin({
165
+ new props.currentBundler.instance.EnvironmentPlugin({
161
166
  // Fallback value required with Webpack 5
162
167
  PWA_SW_CUSTOM: swCustom ?? '',
163
168
  }),
164
- new WebpackBar({
169
+ new ProgressBarPlugin({
165
170
  name: 'Service Worker',
166
171
  color: 'red',
167
172
  }),
@@ -177,7 +182,10 @@ export default function pluginPWA(
177
182
  },
178
183
  };
179
184
 
180
- await compile([swWebpackConfig]);
185
+ await compile({
186
+ configs: [swWebpackConfig],
187
+ currentBundler: props.currentBundler,
188
+ });
181
189
 
182
190
  const swDest = path.resolve(props.outDir, 'sw.js');
183
191
 
@@ -6,7 +6,7 @@
6
6
  */
7
7
 
8
8
  import React from 'react';
9
- import ReactDOM from 'react-dom';
9
+ import {createRoot} from 'react-dom/client';
10
10
  import type {Props} from '@theme/PwaReloadPopup';
11
11
 
12
12
  const POPUP_CONTAINER_ID = 'pwa-popup-container';
@@ -23,6 +23,7 @@ const createContainer = () => {
23
23
  export function renderReloadPopup(props: Props): Promise<void> {
24
24
  const container = getContainer() ?? createContainer();
25
25
  return import('@theme/PwaReloadPopup').then(({default: ReloadPopup}) => {
26
- ReactDOM.render(<ReloadPopup {...props} />, container);
26
+ const root = createRoot(container);
27
+ root.render(<ReloadPopup {...props} />);
27
28
  });
28
29
  }
package/src/sw.ts CHANGED
@@ -20,7 +20,7 @@ function parseSwParams() {
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
- // https://twitter.com/sebastienlorber/status/1280155204575518720
23
+ // https://x.com/sebastienlorber/status/1280155204575518720
24
24
  // but looks it's working fine as it's inlined by webpack, need to double check
25
25
  async function runSWCustomCode(params: {offlineMode: boolean; debug: boolean}) {
26
26
  if (process.env.PWA_SW_CUSTOM) {
package/src/deps.d.ts DELETED
@@ -1,15 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- // TODO incompatible declaration file: https://github.com/unjs/webpackbar/pull/108
9
- declare module 'webpackbar' {
10
- import webpack from 'webpack';
11
-
12
- export default class WebpackBarPlugin extends webpack.ProgressPlugin {
13
- constructor(options: {name: string; color?: string});
14
- }
15
- }