A Vite plugin for compressing build assets using Node.js built-in compression algorithms (gzip, brotliCompress, deflate) and custom algorithms like zstd. Supports multiple algorithms, custom filenames, tarball creation, and artifact hooks. Current stable version is 2.5.3, released under MIT license. Differentiates from vite-plugin-compression by supporting multiple algorithms in one plugin, zstd via Node.js built-in, and better TypeScript typing.
npm install vite-plugin-compression2Verified import paths — ran on the pinned version, not inferred.
Basic Vite configuration enabling gzip and brotli compression for build assets, with minimum size threshold.
Use `include` and `exclude` options instead of `filter`.
Use default filename pattern or provide a string with placeholders (e.g., `[path][base].gz`).
Use `algorithms: ['gzip']` instead of `algorithm: 'gzip'`.
Ensure Node.js version >= 19 for zstd support, or use a custom algorithm.
Set `deleteOriginalAssets: false` or use the tarball plugin to archive.
Install the correct package: `npm install vite-plugin-compression2 -D`
Use `algorithms: ['gzip']` (array) instead of `algorithms: 'gzip'`.
Use `import { compression } from 'vite-plugin-compression2'`No dependency data recorded yet.