Skip to content

esbuild plugin to compress output using gzip, brotli, and deflate.

License

Notifications You must be signed in to change notification settings

Liber-UFPE/esbuild-plugin-compress

Repository files navigation

esbuild-plugin-compress

Build CodeQL NPM Version

An esbuild plugin to compress output using gzip, brotli, and deflate. Based on Node's zlib API.

Install

npm install @liber-ufpe/esbuild-plugin-compress --save-dev

Usage

Important

metafile: true option is required to generate the compressed files. See more about metafile in esbuild docs.

import esbuild from "esbuild";
import compressPlugin from "@liber-ufpe/esbuild-plugin-compress";

const compress = compressPlugin();

esbuild.build({
  entryPoints: ["src/index.js"],
  bundle: true,
  metafile: true,
  outfile: "dist/index.js",
  plugins: [compress],
}).catch(() => process.exit(1));

Or when customizing the compression options:

import esbuild from "esbuild";
import compressPlugin from "@liber-ufpe/esbuild-plugin-compress";

const compress = compressPlugin({
  gzip: true,
  brotli: false,
  gzipOptions: { level: constants.Z_BEST_SPEED },
  deflateOptions: { level: constants.Z_DEFAULT_COMPRESSION },
  excludes: ["**/*.{webp,avif,jpg,png}"]
});

esbuild.build({
  entryPoints: ["src/index.js"],
  bundle: true,
  metafile: true,
  outfile: "dist/index.js",
  plugins: [compress],
}).catch(() => process.exit(1));

Options

  • gzip: Enable gzip compression.
    • type: boolean
    • default: true
  • brotli: Enable brotli compression.
    • type: boolean
    • default: true
  • deflate: Enable deflate compression.
    • type: boolean
    • default: true
  • excludes: glob patterns to exclude files from compression.
    • type: string[]
    • default: []
  • gzipOptions: ZlibOptions for gzip compression.
    • type: ZlibOptions
    • default: {level: constants.Z_BEST_COMPRESSION}
  • deflateOptions: ZlibOptions for deflate compression.
    • type: ZlibOptions
    • default: {level: constants.Z_BEST_COMPRESSION}
  • brotliOptions: BrotliOptions for brotli compression.
    • type: BrotliOptions
    • default: {}

About

esbuild plugin to compress output using gzip, brotli, and deflate.

Resources

License

Stars

Watchers

Forks

Packages

No packages published