types.ts 1.8 KB
Newer Older
陈文彬 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
import type { ZlibOptions } from 'zlib';

export type StringMappingOption = (originalString: string) => string;
export type CustomCompressionOption = (
  content: string | Buffer
) => string | Buffer | Promise<string | Buffer>;

export interface GzipPluginOptions {
  /**
   * Control which of the output files to compress
   *
   * Defaults to `/\.(js|mjs|json|css|html)$/`
   */
  filter?: RegExp | ((fileName: string) => boolean);

  /**
   * GZIP compression options, see https://nodejs.org/api/zlib.html#zlib_class_options
   */
  gzipOptions?: ZlibOptions;

  /**
   * Specified the minimum size in Bytes for a file to get compressed.
   * Files that are smaller than this threshold will not be compressed.
   * This does not apply to the files specified through `additionalFiles`!
   */
  minSize?: number;

  /**
   * This option allows you to compress additional files outside of the main rollup bundling process.
   * The processing is delayed to make sure the files are written on disk; the delay is controlled
   * through `additionalFilesDelay`.
   */
  additionalFiles?: string[];

  /**
   * This options sets a delay (ms) before the plugin compresses the files specified through `additionalFiles`.
   * Increase this value if your artifacts take a long time to generate.
   *
   * Defaults to `2000`
   */
  additionalFilesDelay?: number;

  /**
   * Set a custom compression algorithm. The function can either return the compressed contents synchronously,
   * or otherwise return a promise for asynchronous processing.
   */
  customCompression?: CustomCompressionOption;

  /**
   * Set a custom file name convention for the compressed files. Can be a suffix string or a function
   * returning the file name.
   *
   * Defaults to `.gz`
   */
  fileName?: string | StringMappingOption;
}