@@ -50,6 +50,9 @@ const imageInlineSizeLimit = parseInt(
50
50
process . env . IMAGE_INLINE_SIZE_LIMIT || '10000'
51
51
) ;
52
52
53
+ // Check if Service Worker is setup
54
+ const useServiceWorker = fs . existsSync ( paths . appServiceWorkerJs ) ;
55
+
53
56
// Check if TypeScript is setup
54
57
const useTypeScript = fs . existsSync ( paths . appTsConfig ) ;
55
58
@@ -170,6 +173,9 @@ module.exports = function(webpackEnv) {
170
173
// require.resolve('webpack/hot/dev-server'),
171
174
isEnvDevelopment &&
172
175
require . resolve ( 'react-dev-utils/webpackHotDevClient' ) ,
176
+ // Add service worker if it's available.
177
+ isEnvProduction && useServiceWorker &&
178
+ paths . appServiceWorkerJs ,
173
179
// Finally, this is your app's code:
174
180
paths . appIndexJs ,
175
181
// We include the app code last so that if there is a runtime error during
@@ -674,23 +680,15 @@ module.exports = function(webpackEnv) {
674
680
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
675
681
// You can remove this if you don't use Moment.js:
676
682
new webpack . IgnorePlugin ( / ^ \. \/ l o c a l e $ / , / m o m e n t $ / ) ,
677
- // Generate a service worker script that will precache, and keep up to date,
678
- // the HTML & assets that are part of the Webpack build.
683
+ // Inject a manifest into a service worker script that would allow
684
+ // precaching, and keep up to date, the HTML & assets that are part of
685
+ // the Webpack build.
679
686
isEnvProduction &&
680
- new WorkboxWebpackPlugin . GenerateSW ( {
681
- clientsClaim : true ,
687
+ useServiceWorker &&
688
+ new WorkboxWebpackPlugin . InjectManifest ( {
689
+ swSrc : paths . appServiceWorkerJs ,
682
690
exclude : [ / \. m a p $ / , / a s s e t - m a n i f e s t \. j s o n $ / ] ,
683
691
importWorkboxFrom : 'cdn' ,
684
- navigateFallback : publicUrl + '/index.html' ,
685
- navigateFallbackBlacklist : [
686
- // Exclude URLs starting with /_, as they're likely an API call
687
- new RegExp ( '^/_' ) ,
688
- // Exclude any URLs whose last part seems to be a file extension
689
- // as they're likely a resource and not a SPA route.
690
- // URLs containing a "?" character won't be blacklisted as they're likely
691
- // a route with query params (e.g. auth callbacks).
692
- new RegExp ( '/[^/?]+\\.[^/]+$' ) ,
693
- ] ,
694
692
} ) ,
695
693
// TypeScript type checking
696
694
useTypeScript &&
0 commit comments