sw-template.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. "use strict";
  2. /*
  3. Copyright 2018 Google LLC
  4. Use of this source code is governed by an MIT-style
  5. license that can be found in the LICENSE file or at
  6. https://opensource.org/licenses/MIT.
  7. */
  8. module.exports = `/**
  9. * Welcome to your Workbox-powered service worker!
  10. *
  11. * You'll need to register this file in your web app.
  12. * See https://goo.gl/nhQhGp
  13. *
  14. * The rest of the code is auto-generated. Please don't update this file
  15. * directly; instead, make changes to your Workbox build configuration
  16. * and re-run your build process.
  17. * See https://goo.gl/2aRDsh
  18. */
  19. <% if (importScripts) { %>
  20. importScripts(
  21. <%= importScripts.map(JSON.stringify).join(',\\n ') %>
  22. );
  23. <% } %>
  24. <% if (navigationPreload) { %><%= use('workbox-navigation-preload', 'enable') %>();<% } %>
  25. <% if (cacheId) { %><%= use('workbox-core', 'setCacheNameDetails') %>({prefix: <%= JSON.stringify(cacheId) %>});<% } %>
  26. <% if (skipWaiting) { %>
  27. <%= use('workbox-core', 'skipWaiting') %>();
  28. <% } else { %>
  29. self.addEventListener('message', (event) => {
  30. if (event.data && event.data.type === 'SKIP_WAITING') {
  31. self.skipWaiting();
  32. }
  33. });
  34. <% } %>
  35. <% if (clientsClaim) { %><%= use('workbox-core', 'clientsClaim') %>();<% } %>
  36. <% if (Array.isArray(manifestEntries) && manifestEntries.length > 0) {%>
  37. /**
  38. * The precacheAndRoute() method efficiently caches and responds to
  39. * requests for URLs in the manifest.
  40. * See https://goo.gl/S9QRab
  41. */
  42. <%= use('workbox-precaching', 'precacheAndRoute') %>(<%= JSON.stringify(manifestEntries, null, 2) %>, <%= precacheOptionsString %>);
  43. <% if (cleanupOutdatedCaches) { %><%= use('workbox-precaching', 'cleanupOutdatedCaches') %>();<% } %>
  44. <% if (navigateFallback) { %><%= use('workbox-routing', 'registerRoute') %>(new <%= use('workbox-routing', 'NavigationRoute') %>(<%= use('workbox-precaching', 'createHandlerBoundToURL') %>(<%= JSON.stringify(navigateFallback) %>)<% if (navigateFallbackAllowlist || navigateFallbackDenylist) { %>, {
  45. <% if (navigateFallbackAllowlist) { %>allowlist: [<%= navigateFallbackAllowlist %>],<% } %>
  46. <% if (navigateFallbackDenylist) { %>denylist: [<%= navigateFallbackDenylist %>],<% } %>
  47. }<% } %>));<% } %>
  48. <% } %>
  49. <% if (runtimeCaching) { runtimeCaching.forEach(runtimeCachingString => {%><%= runtimeCachingString %><% });} %>
  50. <% if (offlineAnalyticsConfigString) { %><%= use('workbox-google-analytics', 'initialize') %>(<%= offlineAnalyticsConfigString %>);<% } %>
  51. <% if (disableDevLogs) { %>self.__WB_DISABLE_DEV_LOGS = true;<% } %>`;