types.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import type { ZlibOptions } from 'zlib';
  2. export type StringMappingOption = (originalString: string) => string;
  3. export type CustomCompressionOption = (
  4. content: string | Buffer
  5. ) => string | Buffer | Promise<string | Buffer>;
  6. export interface GzipPluginOptions {
  7. /**
  8. * Control which of the output files to compress
  9. *
  10. * Defaults to `/\.(js|mjs|json|css|html)$/`
  11. */
  12. filter?: RegExp | ((fileName: string) => boolean);
  13. /**
  14. * GZIP compression options, see https://nodejs.org/api/zlib.html#zlib_class_options
  15. */
  16. gzipOptions?: ZlibOptions;
  17. /**
  18. * Specified the minimum size in Bytes for a file to get compressed.
  19. * Files that are smaller than this threshold will not be compressed.
  20. * This does not apply to the files specified through `additionalFiles`!
  21. */
  22. minSize?: number;
  23. /**
  24. * This option allows you to compress additional files outside of the main rollup bundling process.
  25. * The processing is delayed to make sure the files are written on disk; the delay is controlled
  26. * through `additionalFilesDelay`.
  27. */
  28. additionalFiles?: string[];
  29. /**
  30. * This options sets a delay (ms) before the plugin compresses the files specified through `additionalFiles`.
  31. * Increase this value if your artifacts take a long time to generate.
  32. *
  33. * Defaults to `2000`
  34. */
  35. additionalFilesDelay?: number;
  36. /**
  37. * Set a custom compression algorithm. The function can either return the compressed contents synchronously,
  38. * or otherwise return a promise for asynchronous processing.
  39. */
  40. customCompression?: CustomCompressionOption;
  41. /**
  42. * Set a custom file name convention for the compressed files. Can be a suffix string or a function
  43. * returning the file name.
  44. *
  45. * Defaults to `.gz`
  46. */
  47. fileName?: string | StringMappingOption;
  48. }