# vite-plugin-compression **Repository Path**: mirrors_silverwind/vite-plugin-compression ## Basic Information - **Project Name**: vite-plugin-compression - **Description**: vite plugin. compress your bundle file. - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-07-16 - **Last Updated**: 2026-05-17 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README

[![codecov](https://codecov.io/gh/nonzzz/vite-plugin-compression/branch/master/graph/badge.svg?token=NG4475OP6B)](https://codecov.io/gh/nonzzz/vite-compression-plugin) ## Install ```bash $ yarn add vite-plugin-compression2 -D # or $ npm install vite-plugin-compression2 -D ``` ## Usage ```js import { defineConfig } from 'vite' import { compression } from 'vite-plugin-compression2' export default defineConfig({ plugins: [ // ...your plugin compression() ] }) ``` ## Options | params | type | default | description | | ---------------------- | --------------------------------------------- | ------------------------------------------- | ------------------------------------------------------------------------------------------ | | `include` | `string \| RegExp \| Array` | `/\.(html\|xml\|css\|json\|js\|mjs\|svg)$/` | Include all assets matching any of these conditions. | | `exclude` | `string \| RegExp \| Array` | `-` | Exclude all assets matching any of these conditions. | | `threshold` | `number` | `0` | Only assets bigger than this size are processed (in bytes) | | `algorithm` | `string\| function` | `gzip` | The compression algorithm | | `compressionOptions` | `Record` | `{}` | Compression options for `algorithm`(details see `zlib module`) | | `deleteOriginalAssets` | `boolean` | `false` | Whether to delete the original assets or not | | `skipIfLargerOrEqual` | `boolean` | `true` | Whether to skip the compression if the result is larger than or equal to the original file | | `filename` | `string` | `[path][base].gz` | The target asset filename | ## Q & A > Why not vite-plugin-compression - `vite-plugin-compression` no longer maintenance. > Why vite-plugin-compression2 - `vite-plugin-compression2` has minimal dependencies and better performance. > Can i custom the compression algorithm? - Yes, you can see the unit test case. > Can i generate multiple compressed assets with difference compression algorithm? ```js import { defineComponent } from 'vite' import { compression } from 'vite-plugin-compression2' export default defineComponent({ plugins: [ // ...your plugin compression(), compression({ algorithm: 'brotliCompress' }) ] }) ``` > Can i create a tarball for all of assets after compressed? - Yes, you can import `tarball` plugin from this package(>=1.0.0) ```js import { defineComponent } from 'vite' import { compression, tarball } from 'vite-plugin-compression2' export default defineComponent({ plugins: [ // ...your plugin compression(), tarball() ] }) ``` ### Others - If you want to analysis your bundle assets. Maybe you can try [vite-bundle-analyzer](https://github.com/nonzzz/vite-bundle-analyzer) - `tarball` option `dest` means to generate a tarball somewhere - `tarball` is based on the `ustart`. It should be compatible with all popular tar distributions out there (gnutar, bsdtar etc) ### Sponsors

### LICENSE [MIT](./LICENSE) ### Author Kanno