@serwist/build
Version:
A module that integrates into your build process, helping you generate a manifest of local files that should be precached.
61 lines • 2.72 kB
TypeScript
import type { BaseResolved, FileDetails, ManifestEntry } from "../types.js";
/**
* A `ManifestTransform` function can be used to modify the modify the `url` or
* `revision` properties of some or all of the {@linkcode ManifestEntry} in the manifest.
*
* Deleting the `revision` property of an entry will cause
* the corresponding `url` to be precached without cache-busting parameters
* applied, which is to say, it implies that the URL itself contains
* proper versioning info. If the `revision` property is present, it must be
* set to a string.
*
* @example A transformation that prepended the origin of a CDN for any
* URL starting with '/assets/' could be implemented as:
*
* const cdnTransform = async (manifestEntries) => {
* const manifest = manifestEntries.map(entry => {
* const cdnOrigin = 'https://example.com';
* if (entry.url.startsWith('/assets/')) {
* entry.url = cdnOrigin + entry.url;
* }
* return entry;
* });
* return {manifest, warnings: []};
* };
*
* @example A transformation that nulls the revision field when the
* URL contains an 8-character hash surrounded by '.', indicating that it
* already contains revision information:
*
* const removeRevisionTransform = async (manifestEntries) => {
* const manifest = manifestEntries.map(entry => {
* const hashRegExp = /\.\w{8}\./;
* if (entry.url.match(hashRegExp)) {
* entry.revision = null;
* }
* return entry;
* });
* return {manifest, warnings: []};
* };
*
* @callback ManifestTransform
* @param manifestEntries The full
* array of entries, prior to the current transformation.
* @param compilation When used in the webpack plugins, this param
* will be set to the current `compilation`.
* @returns The array of entries with the transformation applied,
* and optionally, any warnings that should be reported back to the build tool.
*/
interface ManifestTransformResultWithWarnings {
count: number;
size: number;
manifestEntries: ManifestEntry[] | undefined;
warnings: string[];
}
interface TransformManifestOptions extends Pick<BaseResolved, "additionalPrecacheEntries" | "dontCacheBustURLsMatching" | "manifestTransforms" | "maximumFileSizeToCacheInBytes" | "modifyURLPrefix" | "disablePrecacheManifest"> {
fileDetails: FileDetails[];
transformParam?: unknown;
}
export declare function transformManifest({ additionalPrecacheEntries, dontCacheBustURLsMatching, fileDetails, manifestTransforms, maximumFileSizeToCacheInBytes, modifyURLPrefix, transformParam, disablePrecacheManifest, }: TransformManifestOptions): Promise<ManifestTransformResultWithWarnings>;
export {};
//# sourceMappingURL=transform-manifest.d.ts.map