@@ -53,6 +53,9 @@ const imageInlineSizeLimit = parseInt(
53
53
// Check if TypeScript is setup
54
54
const useTypeScript = fs . existsSync ( paths . appTsConfig ) ;
55
55
56
+ // Check if service worker template is setup
57
+ const useServiceWorkerTemplate = fs . existsSync ( paths . serviceWorkerTemplate ) ;
58
+
56
59
// style files regexes
57
60
const cssRegex = / \. c s s $ / ;
58
61
const cssModuleRegex = / \. m o d u l e \. c s s $ / ;
@@ -671,6 +674,25 @@ module.exports = function(webpackEnv) {
671
674
// Generate a service worker script that will precache, and keep up to date,
672
675
// the HTML & assets that are part of the Webpack build.
673
676
isEnvProduction &&
677
+ ! useServiceWorkerTemplate &&
678
+ new WorkboxWebpackPlugin . GenerateSW ( {
679
+ clientsClaim : true ,
680
+ exclude : [ / \. m a p $ / , / a s s e t - m a n i f e s t \. j s o n $ / ] ,
681
+ importWorkboxFrom : 'cdn' ,
682
+ navigateFallback : paths . publicUrlOrPath + 'index.html' ,
683
+ navigateFallbackDenylist : [
684
+ // Exclude URLs starting with /_, as they're likely an API call
685
+ new RegExp ( '^/_' ) ,
686
+ // Exclude any URLs whose last part seems to be a file extension
687
+ // as they're likely a resource and not a SPA route.
688
+ // URLs containing a "?" character won't be blacklisted as they're likely
689
+ // a route with query params (e.g. auth callbacks).
690
+ new RegExp ( '/[^/?]+\\.[^/]+$' ) ,
691
+ ] ,
692
+ } ) ,
693
+ // If app has file sw-template.js, workbox use this configuration for generate a advanced config based in template
694
+ isEnvProduction &&
695
+ useServiceWorkerTemplate &&
674
696
new WorkboxWebpackPlugin . InjectManifest ( {
675
697
exclude : [ / \. m a p $ / , / a s s e t - m a n i f e s t \. j s o n $ / ] ,
676
698
swSrc : `${ paths . appSrc } /sw-template.${ useTypeScript ? 'ts' : 'js' } ` ,
0 commit comments