transform-manifest.d.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { BasePartial, FileDetails, ManifestEntry } from '../types';
  2. /**
  3. * A `ManifestTransform` function can be used to modify the modify the `url` or
  4. * `revision` properties of some or all of the
  5. * {@link workbox-build.ManifestEntry} in the manifest.
  6. *
  7. * Deleting the `revision` property of an entry will cause
  8. * the corresponding `url` to be precached without cache-busting parameters
  9. * applied, which is to say, it implies that the URL itself contains
  10. * proper versioning info. If the `revision` property is present, it must be
  11. * set to a string.
  12. *
  13. * @example A transformation that prepended the origin of a CDN for any
  14. * URL starting with '/assets/' could be implemented as:
  15. *
  16. * const cdnTransform = async (manifestEntries) => {
  17. * const manifest = manifestEntries.map(entry => {
  18. * const cdnOrigin = 'https://example.com';
  19. * if (entry.url.startsWith('/assets/')) {
  20. * entry.url = cdnOrigin + entry.url;
  21. * }
  22. * return entry;
  23. * });
  24. * return {manifest, warnings: []};
  25. * };
  26. *
  27. * @example A transformation that nulls the revision field when the
  28. * URL contains an 8-character hash surrounded by '.', indicating that it
  29. * already contains revision information:
  30. *
  31. * const removeRevisionTransform = async (manifestEntries) => {
  32. * const manifest = manifestEntries.map(entry => {
  33. * const hashRegExp = /\.\w{8}\./;
  34. * if (entry.url.match(hashRegExp)) {
  35. * entry.revision = null;
  36. * }
  37. * return entry;
  38. * });
  39. * return {manifest, warnings: []};
  40. * };
  41. *
  42. * @callback ManifestTransform
  43. * @param {Array<workbox-build.ManifestEntry>} manifestEntries The full
  44. * array of entries, prior to the current transformation.
  45. * @param {Object} [compilation] When used in the webpack plugins, this param
  46. * will be set to the current `compilation`.
  47. * @return {Promise<workbox-build.ManifestTransformResult>}
  48. * The array of entries with the transformation applied, and optionally, any
  49. * warnings that should be reported back to the build tool.
  50. *
  51. * @memberof workbox-build
  52. */
  53. interface ManifestTransformResultWithWarnings {
  54. count: number;
  55. size: number;
  56. manifestEntries: ManifestEntry[];
  57. warnings: string[];
  58. }
  59. export declare function transformManifest({ additionalManifestEntries, dontCacheBustURLsMatching, fileDetails, manifestTransforms, maximumFileSizeToCacheInBytes, modifyURLPrefix, transformParam, }: BasePartial & {
  60. fileDetails: Array<FileDetails>;
  61. transformParam?: unknown;
  62. }): Promise<ManifestTransformResultWithWarnings>;
  63. export {};