compression-rspack-plugin

March 30, 2026 · View on GitHub

npm version CI license npm downloads coverage awesome-rstack

Rust-native parallel compression plugin for Rspack. Drop-in replacement for compression-webpack-plugin.

Compresses assets in parallel across all CPU cores via Rust + rayon, instead of serially on the Node.js main thread.

Install

npm install compression-rspack-plugin
# or
pnpm add compression-rspack-plugin
# or
yarn add compression-rspack-plugin

Prebuilt binaries are available for macOS (arm64, x64), Linux (x64 glibc, arm64 glibc, x64 musl). The correct binary is installed automatically via platform-specific optional dependencies.

Usage

import { CompressionRspackPlugin } from 'compression-rspack-plugin'

export default {
  plugins: [
    new CompressionRspackPlugin({ test: /\.(js|css|html|json|svg)$/ }),
    new CompressionRspackPlugin({ algorithm: 'brotliCompress', test: /\.(js|css|html|json|svg)$/ }),
  ],
}

Options

Same interface as compression-webpack-plugin. Validated via schema-utils.

OptionTypeDefaultDescription
algorithmstring | Function"gzip""gzip", "brotliCompress", "deflate", "deflateRaw", or custom callback
compressionOptionsobject{}Passed to the algorithm. Defaults to max quality per algorithm.
filenamestring | Function"[path][base].gz"Output template. "[path][base].br" for brotli.
testRegExp | string | ArrayInclude matching assets
includeRegExp | string | ArrayInclude matching assets
excludeRegExp | string | ArrayExclude matching assets
thresholdnumber0Min size in bytes
minRationumber0.8Only emit if compressed/original < this
deleteOriginalAssetsboolean | "keep-source-map" | FunctionfalseRemove originals after compression

Benchmarks

Tested on a production Rspack build (~1,400 assets, Apple M3 Pro 14-core).

compression-webpack-plugincompression-rspack-plugin
Build time (avg of 3)82.7s37.3s (2.2x faster)
Compression phase (RsDoctor)61.1s20.3s (3.0x faster)
.gz files1,4101,411
.br files1,4441,444
gzip-6 / 1 KB106 MiB/s143 MiB/s (1.4x)
gzip-6 / 100 KB0.66 GiB/s2.77 GiB/s (4.2x)
gzip-6 / 1 MB0.66 GiB/s3.30 GiB/s (5.0x)
deflate-6 / 1 MB0.69 GiB/s2.03 GiB/s (2.9x)

How it works

Built-in algorithms (gzip, brotliCompress, deflate, deflateRaw) are handled by flate2 and brotli in Rust via a single napi-rs FFI call. Custom algorithms fall back to Node.js zlib.

Differences from compression-webpack-plugin

compression-webpack-plugincompression-rspack-plugin
CompressionNode.js zlib (serial)Rust rayon (parallel) + zlib fallback
Compilation cacheYesNot yet
Child compilationsYes (scoped via thisCompilation)Yes
[compressed] stats flagYesRegistered, not rendered by rspack 2.0 beta

Development

pnpm install        # install deps
pnpm build          # native addon + TypeScript
pnpm test           # JS tests (120 tests)
pnpm test:rust      # Rust unit tests
pnpm lint           # biome
pnpm lint:rs        # cargo fmt + clippy
pnpm typecheck      # tsc --noEmit

License

MIT