UNPKG

5.34 kBTypeScriptView Raw
1import { BuildResult } from './types';
2/**
3 * This method creates a list of URLs to precache, referred to as a "precache
4 * manifest", based on the options you provide.
5 *
6 * The manifest is injected into the `swSrc` file, and the placeholder string
7 * `injectionPoint` determines where in the file the manifest should go.
8 *
9 * The final service worker file, with the manifest injected, is written to
10 * disk at `swDest`.
11 *
12 * @param {Object} config The configuration to use.
13 *
14 * @param {string} config.globDirectory The local directory you wish to match
15 * `globPatterns` against. The path is relative to the current directory.
16 *
17 * @param {string} config.swDest The path and filename of the service worker file
18 * that will be created by the build process, relative to the current working
19 * directory. It must end in '.js'.
20 *
21 * @param {string} config.swSrc The path and filename of the service worker file
22 * that will be read during the build process, relative to the current working
23 * directory.
24 *
25 * @param {Array<module:workbox-build.ManifestEntry>} [config.additionalManifestEntries]
26 * A list of entries to be precached, in addition to any entries that are
27 * generated as part of the build configuration.
28 *
29 * @param {RegExp} [config.dontCacheBustURLsMatching] Assets that match this will be
30 * assumed to be uniquely versioned via their URL, and exempted from the normal
31 * HTTP cache-busting that's done when populating the precache. While not
32 * required, it's recommended that if your existing build process already
33 * inserts a `[hash]` value into each filename, you provide a RegExp that will
34 * detect that, as it will reduce the bandwidth consumed when precaching.
35 *
36 * @param {boolean} [config.globFollow=true] Determines whether or not symlinks
37 * are followed when generating the precache manifest. For more information, see
38 * the definition of `follow` in the `glob`
39 * [documentation](https://github.com/isaacs/node-glob#options).
40 *
41 * @param {Array<string>} [config.globIgnores=['node_modules/**']]
42 * A set of patterns matching files to always exclude when generating the
43 * precache manifest. For more information, see the definition of `ignore` in the `glob`
44 * [documentation](https://github.com/isaacs/node-glob#options).
45 *
46 * @param {Array<string>} [config.globPatterns=['**.{js,css,html}']]
47 * Files matching any of these patterns will be included in the precache
48 * manifest. For more information, see the
49 * [`glob` primer](https://github.com/isaacs/node-glob#glob-primer).
50 *
51 * @param {boolean} [config.globStrict=true] If true, an error reading a directory when
52 * generating a precache manifest will cause the build to fail. If false, the
53 * problematic directory will be skipped. For more information, see the
54 * definition of `strict` in the `glob`
55 * [documentation](https://github.com/isaacs/node-glob#options).
56 *
57 * @param {string} [config.injectionPoint='self.__WB_MANIFEST'] The string to
58 * find inside of the `swSrc` file. Once found, it will be replaced by the
59 * generated precache manifest.
60 *
61 * @param {Array<module:workbox-build.ManifestTransform>} [config.manifestTransforms] One or more
62 * functions which will be applied sequentially against the generated manifest.
63 * If `modifyURLPrefix` or `dontCacheBustURLsMatching` are also specified, their
64 * corresponding transformations will be applied first.
65 *
66 * @param {number} [config.maximumFileSizeToCacheInBytes=2097152] This value can be
67 * used to determine the maximum size of files that will be precached. This
68 * prevents you from inadvertently precaching very large files that might have
69 * accidentally matched one of your patterns.
70 *
71 * @param {object<string, string>} [config.modifyURLPrefix] A mapping of prefixes
72 * that, if present in an entry in the precache manifest, will be replaced with
73 * the corresponding value. This can be used to, for example, remove or add a
74 * path prefix from a manifest entry if your web hosting setup doesn't match
75 * your local filesystem setup. As an alternative with more flexibility, you can
76 * use the `manifestTransforms` option and provide a function that modifies the
77 * entries in the manifest using whatever logic you provide.
78 *
79 * @param {Object} [config.templatedURLs] If a URL is rendered based on some
80 * server-side logic, its contents may depend on multiple files or on some other
81 * unique string value. The keys in this object are server-rendered URLs. If the
82 * values are an array of strings, they will be interpreted as `glob` patterns,
83 * and the contents of any files matching the patterns will be used to uniquely
84 * version the URL. If used with a single string, it will be interpreted as
85 * unique versioning information that you've generated for a given URL.
86 *
87 * @return {Promise<{count: number, filePaths: Array<string>, size: number, warnings: Array<string>}>}
88 * A promise that resolves once the service worker and related files
89 * (indicated by `filePaths`) has been written to `swDest`. The `size` property
90 * contains the aggregate size of all the precached entries, in bytes, and the
91 * `count` property contains the total number of precached entries. Any
92 * non-fatal warning messages will be returned via `warnings`.
93 *
94 * @memberof module:workbox-build
95 */
96export declare function injectManifest(config: unknown): Promise<BuildResult>;