# vite-plugin-compression

> Use gzip or brotli to compress resources.

Latest version **0.5.1** (published 2022-01-29) · MIT license · 569.5K weekly downloads

## Install

```sh
npm install vite-plugin-compression
pnpm add vite-plugin-compression
yarn add vite-plugin-compression
bun add vite-plugin-compression
```

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: moderate downloads; has types; esm support; no vulnerabilities.

Warnings: pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.1 |
| Published | 2022-01-29 |
| First published | 2021-02-04 |
| Weekly downloads | 569.5K |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 15.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 466 |
| Author | Vben |
| Maintainers | vvben |
| Keywords | vite, vite-plugin, imagemin, vben |

## Links

- npm: https://www.npmjs.com/package/vite-plugin-compression
- Repository: https://github.com/anncwb/vite-plugin-compression
- Homepage: https://github.com/anncwb/vite-plugin-compression/tree/master/#readme
- Issues: https://github.com/anncwb/vite-plugin-compression/issues
- npm.io page: https://npm.io/package/vite-plugin-compression

## Dependencies (3)

- [chalk](https://npm.io/package/chalk.md) ^4.1.2
- [debug](https://npm.io/package/debug.md) ^4.3.3
- [fs-extra](https://npm.io/package/fs-extra.md) ^10.0.0

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads
- [ionic-img-viewer](https://npm.io/package/ionic-img-viewer.md) — 448 weekly downloads

## Recent versions

- 0.5.1 (latest) — 2022-01-29
- 0.5.0 — 2022-01-28
- 0.4.0 — 2021-12-28
- 0.3.6 — 2021-11-25
- 0.3.5 — 2021-08-23
- 0.3.3 — 2021-08-01
- 0.3.2 — 2021-08-01
- 0.3.1 — 2021-07-18
- 0.2.6 — 2021-07-18
- 0.3.0 — 2021-07-05
- 0.2.5 — 2021-05-09
- 0.2.4 — 2021-04-03
- 0.2.3 — 2021-03-02
- 0.2.2 — 2021-02-23
- 0.2.1 — 2021-02-11
- … 2 more at https://npm.io/package/vite-plugin-compression/versions

## README

# vite-plugin-compression

**English** | [中文](./README.zh_CN.md)

[![npm][npm-img]][npm-url] [![node][node-img]][node-url]

Use `gzip` or `brotli` to compress resources.

Since [vite-plugin-compress](https://github.com/alloc/vite-plugin-compress) does not support `gzip` compression, a separate copy has been modified and some functions have been added.

## Install (yarn or npm)

**node version:** >=12.0.0

**vite version:** >=2.0.0

```
yarn add vite-plugin-compression -D
```

or

```
npm i vite-plugin-compression -D
```

## Usage

- Configuration plugin in vite.config.ts

```ts
import viteCompression from 'vite-plugin-compression';

export default () => {
  return {
    plugins: [viteCompression()],
  };
};
```

### Options

| params | type | default | default |
| --- | --- | --- | --- |
| verbose | `boolean` | `true` | Whether to output the compressed result in the console |
| filter | `RegExp or (file: string) => boolean` | `DefaultFilter` | Specify which resources are not compressed |
| disable | `boolean` | `false` | Whether to disable |
| threshold | `number` | `1025` | It will be compressed if the volume is larger than threshold, the unit is b |
| algorithm | `string` | `gzip` | Compression algorithm, optional ['gzip','brotliCompress' ,'deflate','deflateRaw'] |
| ext | `string` | `.gz` | Suffix of the generated compressed package |
| compressionOptions | `object` | - | The parameters of the corresponding compression algorithm |
| deleteOriginFile | `boolean` | - | Whether to delete source files after compression |

**DefaultFilter**

`/\.(js|mjs|json|css|html)$/i`

## Example

**Run Example**

```bash

cd ./example

yarn install

yarn test:gzip

yarn test:br

```

## Sample project

[Vben Admin](https://github.com/anncwb/vue-vben-admin)

## License

MIT

## Inspiration

[vite-plugin-compress](https://github.com/alloc/vite-plugin-compress)

[npm-img]: https://img.shields.io/npm/v/vite-plugin-compression.svg
[npm-url]: https://npmjs.com/package/vite-plugin-compression
[node-img]: https://img.shields.io/node/v/vite-plugin-compression.svg
[node-url]: https://nodejs.org/en/about/releases/

---
_Source: https://npm.io/package/vite-plugin-compression · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
