Repalce old sw-precache-webpack-plugin Plugin to workbox-webpack-plugin.
It also allow you to add serviceWorker.js
to extend the service-worker.js
generated in webpack build.
Like what importScripts
did in sw-precache-webpack-plugin
.
Example Usage:
Modify crs.config
as below.
const { compose } = require('create-react-scripts')
module.exports = compose(
require('create-react-scripts-workbox')(/* options passed to sass-loader*/),
...
);
Please make sure you read the follwing issues. (GoogleChrome/workbox#672) (GoogleChrome/workbox#795)
Create serviceWorker.js
under your application folder
importScripts('https://unpkg.com/workbox-sw@0.0.2');
const workboxSW = new WorkboxSW({clientsClaim: true});
// This array will be populated by workboxBuild.injectManifest() when the
// production service worker is generated.
workboxSW.precache([]);
workboxSW.router.setDefaultHandler({
handler: workboxSW.strategies.staleWhileRevalidate()
});