Skip to content

Commit 3d457d8

Browse files
author
Marlon Maxwel
committed
feat(react-scripts): configure injectManifest with workbox v5
1 parent 268e7ba commit 3d457d8

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed
Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1+
/* eslint-disable no-restricted-globals */
2+
import { clientsClaim } from 'workbox-core';
3+
import { NavigationRoute, registerRoute } from 'workbox-routing';
4+
import { precacheAndRoute, createHandlerBoundToURL } from 'workbox-precaching';
5+
16
self.addEventListener('message', function(event) {
27
if (event.data && event.data.type === 'SKIP_WAITING') {
38
self.skipWaiting();
49
}
510
});
611

7-
workbox.core.clientsClaim();
12+
clientsClaim();
813

9-
self.__precacheManifest = [].concat(self.__precacheManifest || []);
10-
workbox.precaching.precacheAndRoute(self.__precacheManifest, {});
14+
precacheAndRoute(self.__WB_MANIFEST);
1115

12-
workbox.routing.registerNavigationRoute(
13-
workbox.precaching.getCacheKeyForURL('/index.html'),
14-
{
15-
blacklist: [new RegExp('^/_'), new RegExp('/[^/?]+\\.[^/]+$')],
16-
}
17-
);
16+
const handler = createHandlerBoundToURL('/index.html');
17+
18+
const navigationRoute = new NavigationRoute(handler, {
19+
denylist: [new RegExp('^/_'), new RegExp('/[^/?]+\\.[^/]+$')],
20+
});
21+
22+
registerRoute(navigationRoute);

packages/react-scripts/config/webpack.config.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -693,10 +693,10 @@ module.exports = function(webpackEnv) {
693693
// navigateFallback: paths.publicUrlOrPath + 'index.html',
694694
swSrc: `${paths.appSrc}/sw.js`,
695695
swDest: `${paths.appBuild}/service-worker.js`,
696-
globDirectory: paths.appBuild,
697-
importScripts: [
698-
'https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js',
699-
],
696+
// globDirectory: paths.appBuild,
697+
// importScripts: [
698+
// 'https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js',
699+
// ],
700700
}),
701701
// TypeScript type checking
702702
useTypeScript &&

packages/react-scripts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
"webpack": "4.41.5",
8080
"webpack-dev-server": "3.10.2",
8181
"webpack-manifest-plugin": "2.2.0",
82-
"workbox-webpack-plugin": "4.3.1"
82+
"workbox-webpack-plugin": "5.0.0"
8383
},
8484
"devDependencies": {
8585
"react": "^16.12.0",

0 commit comments

Comments
 (0)