Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/alloc/vite-plugin-compress

Compress your bundle + assets from Vite
https://github.com/alloc/vite-plugin-compress

vite vite-plugin

Last synced: 30 days ago
JSON representation

Compress your bundle + assets from Vite

Awesome Lists containing this project

README

        

# vite-plugin-compress

[![npm](https://img.shields.io/npm/v/vite-plugin-compress.svg)](https://www.npmjs.com/package/vite-plugin-compress)
[![Code style: Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://paypal.me/alecdotbiz)

> Compress your bundle + assets from Vite

- Assets generated by Vite and assets from `./public` are compressed with Brotli
- Images, sounds, WOFF2 fonts, and PDFs are *not* compressed with Brotli, since these formats are compressed by default
- SVGs are further optimized with [svgo](https://github.com/svg/svgo)
- PNGs are further optimized with [imagemin](https://github.com/imagemin/imagemin)
- By default, files smaller than 1501 bytes are not compressed, since the [MTU](https://en.wikipedia.org/wiki/Maximum_transmission_unit) of a TCP packet is 1500 bytes
- Compatible with [vite-ssr](https://github.com/frandiox/vite-ssr)
- Just add `exclude: ["ssr-manifest.json"]`

 

## Usage

```ts
import compress from 'vite-plugin-compress'

export default {
plugins: [
compress(),
]
}
```

### Options

- `quality: number`
Higher quality means smaller file sizes.
Defaults to max quality (11).

- `threshold: number`
Minimum file size (in bytes) to be compressed.
Defaults to 1501.

- `exclude: string[]`
Globs to exclude certain files from being compressed.

- `extensions: string[]`
Additional extensions to compress with Brotli.

Default extensions include:
- `.html`
- `.js`
- `.css`
- `.svg`
- `.json`

- `svgo: object`
Options for the SVG optimizer.
More info [here](https://github.com/svg/svgo/#what-it-can-do).

Default plugins include:
- `removeViewBox: false`
- `removeDimensions: true`
- Plugins listed [here](https://github.com/svg/svgo/blob/master/.svgo.yml) are enabled

- `pngquant: object`
Options for the PNG optimizer.
More info [here](https://www.npmjs.com/package/imagemin-pngquant#options).

- `brotli: boolean`
Set to false to disable Brotli compression.

- `verbose: boolean`
Log compressed files and their compression ratios.