@@ -18,7 +18,7 @@ const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
18
18
const safePostCssParser = require ( 'postcss-safe-parser' ) ;
19
19
const ManifestPlugin = require ( 'webpack-manifest-plugin' ) ;
20
20
const InterpolateHtmlPlugin = require ( 'react-dev-utils/InterpolateHtmlPlugin' ) ;
21
- const SWPrecacheWebpackPlugin = require ( 'sw-precache -webpack-plugin' ) ;
21
+ const WorkboxWebpackPlugin = require ( 'workbox -webpack-plugin' ) ;
22
22
const ModuleScopePlugin = require ( 'react-dev-utils/ModuleScopePlugin' ) ;
23
23
const getCSSModuleLocalIdent = require ( 'react-dev-utils/getCSSModuleLocalIdent' ) ;
24
24
const paths = require ( './paths' ) ;
@@ -481,48 +481,27 @@ module.exports = {
481
481
fileName : 'asset-manifest.json' ,
482
482
publicPath : publicPath ,
483
483
} ) ,
484
- // Generate a service worker script that will precache, and keep up to date,
485
- // the HTML & assets that are part of the Webpack build.
486
- new SWPrecacheWebpackPlugin ( {
487
- // By default, a cache-busting query parameter is appended to requests
488
- // used to populate the caches, to ensure the responses are fresh.
489
- // If a URL is already hashed by Webpack, then there is no concern
490
- // about it being stale, and the cache-busting can be skipped.
491
- dontCacheBustUrlsMatching : / \. \w { 8 } \. / ,
492
- filename : 'service-worker.js' ,
493
- logger ( message ) {
494
- if ( message . indexOf ( 'Total precache size is' ) === 0 ) {
495
- // This message occurs for every build and is a bit too noisy.
496
- return ;
497
- }
498
- if ( message . indexOf ( 'Skipping static resource' ) === 0 ) {
499
- // This message obscures real errors so we ignore it.
500
- // https://github.com/facebook/create-react-app/issues/2612
501
- return ;
502
- }
503
- console . log ( message ) ;
504
- } ,
505
- minify : true ,
506
- // For unknown URLs, fallback to the index page
507
- navigateFallback : publicUrl + '/index.html' ,
508
- // Ignores URLs starting from /__ (useful for Firebase):
509
- // https://github.com/facebookincubator/create-react-app/issues/2237#issuecomment-302693219
510
- navigateFallbackWhitelist : [ / ^ (? ! \/ _ _ ) .* / ] ,
511
- // Don't precache sourcemaps (they're large) and build asset manifest:
512
- staticFileGlobsIgnorePatterns : [ / \. m a p $ / , / a s s e t - m a n i f e s t \. j s o n $ / ] ,
513
- // Disabling skipWaiting ensures better compatibility with web apps that
514
- // use deferred or lazy-loading, at the expense of "keeping around" the
515
- // previously cached version of your web app until all open instances have
516
- // been closed.
517
- // See https://developers.google.com/web/fundamentals/primers/service-workers/lifecycle#skip_the_waiting_phase
518
- skipWaiting : false ,
519
- } ) ,
520
484
// Moment.js is an extremely popular library that bundles large locale files
521
485
// by default due to how Webpack interprets its code. This is a practical
522
486
// solution that requires the user to opt into importing specific locales.
523
487
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
524
488
// You can remove this if you don't use Moment.js:
525
489
new webpack . IgnorePlugin ( / ^ \. \/ l o c a l e $ / , / m o m e n t $ / ) ,
490
+ // Generate a service worker script that will precache, and keep up to date,
491
+ // the HTML & assets that are part of the Webpack build.
492
+ new WorkboxWebpackPlugin . GenerateSW ( {
493
+ clientsClaim : true ,
494
+ exclude : [ / \. m a p $ / , / a s s e t - m a n i f e s t \. j s o n $ / ] ,
495
+ importWorkboxFrom : 'local' ,
496
+ navigateFallback : publicUrl + '/index.html' ,
497
+ navigateFallbackBlacklist : [
498
+ // Exclude URLs starting with /_, as they're likely an API call
499
+ new RegExp ( '^/_' ) ,
500
+ // Exclude URLs containing a dot, as they're likely a resource in
501
+ // public/ and not a SPA route
502
+ new RegExp ( '/[^/]+[.][^/]+$' ) ,
503
+ ] ,
504
+ } ) ,
526
505
] ,
527
506
// Some libraries import Node modules but don't use them in the browser.
528
507
// Tell Webpack to provide empty mocks for them so importing them works.
0 commit comments