index.js 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. const copyWorkboxLibraries = require('./lib/copy-workbox-libraries');
  9. const generateSW = require('./entry-points/generate-sw');
  10. const generateSWString = require('./entry-points/generate-sw-string');
  11. const getManifest = require('./entry-points/get-manifest');
  12. const injectManifest = require('./entry-points/inject-manifest');
  13. const _require = require('./lib/cdn-utils'),
  14. getModuleURL = _require.getModuleURL;
  15. /**
  16. * This Node module can be used to generate a list of assets that should be
  17. * precached in a service worker, generating a hash that can be used to
  18. * intelligently update a cache when the service worker is updated.
  19. *
  20. * This module will use glob patterns to find assets in a given directory
  21. * and use the resulting URL and revision data for one of the follow uses:
  22. *
  23. * 1. Generate a complete service worker with precaching and some basic
  24. * configurable options, writing the resulting service worker file to disk. See
  25. * [generateSW()]{@link module:workbox-build.generateSW}.
  26. * 1. Generate a complete service worker with precaching and some basic
  27. * configurable options, without writing the results to disk. See
  28. * [generateSWString()]{@link module:workbox-build.generateSWString}.
  29. * 1. Inject a manifest into an existing service worker. This allows you
  30. * to control your own service worker while still taking advantage of
  31. * [workboxSW.precache()]{@link module:workbox-sw.WorkboxSW#precache} logic.
  32. * See [injectManifest()]{@link module:workbox-build.injectManifest}.
  33. * 1. Just generate a manifest, not a full service worker file.
  34. * This is useful if you want to make use of the manifest from your own existing
  35. * service worker file and are okay with including the manifest yourself.
  36. * See [getManifest()]{@link module:workbox-build.getManifest}.
  37. *
  38. * @property {Array<RegExp>} [ignoreURLParametersMatching=[/^utm_/]] Any
  39. * search parameter names that match against one of the regex's in this array
  40. * will be removed before looking for a precache match.
  41. *
  42. * This is useful if your users might request URLs that contain, for example,
  43. * URL parameters used to track the source of the traffic. Those URL parameters
  44. * would normally cause the cache lookup to fail, since the URL strings used
  45. * as cache keys would not be expected to include them.
  46. *
  47. * You can use `[/./]` to ignore all URL parameters.
  48. *
  49. * Note: This option is only valid when used with
  50. * {@link module:workbox-build#generateSW|generateSW()}. When using
  51. * {@link module:workbox-build.injectManifest|injectManifest()}, you can
  52. * explicitly pass the desired value in to the
  53. * {@link module:workbox-sw.WorkboxSW|WorkboxSW() constructor} in your `swSrc`
  54. * file.
  55. *
  56. * E.g. `[/homescreen/]`
  57. *
  58. * @property {Boolean} [handleFetch=true] Whether or not `workbox-sw` should
  59. * create a `fetch` event handler that responds to network requests. This is
  60. * useful during development if you don't want the service worker serving stale
  61. * content.
  62. *
  63. * Note: This option is only valid when used with
  64. * {@link module:workbox-build#generateSW|generateSW()}. When using
  65. * {@link module:workbox-build.injectManifest|injectManifest()}, you can
  66. * explicitly pass the desired value in to the
  67. * {@link module:workbox-sw.WorkboxSW|WorkboxSW() constructor} in your `swSrc`
  68. * file.
  69. *
  70. * @module workbox-build
  71. */
  72. module.exports = {
  73. copyWorkboxLibraries,
  74. generateSW,
  75. generateSWString,
  76. getManifest,
  77. getModuleURL,
  78. injectManifest
  79. };