UNPKG

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