---
title: "@farmfe/plugin-compress"
locale: "en"
version: "current"
canonicalUrl: "https://farmfe.org/docs/plugins/official-plugins/compress"
publicationStatus: "prerelease"
---

<a id="farmfeplugin-compress"></a>
# @farmfe/plugin-compress


A Rust Farm plugin that compresses generated JavaScript, CSS, HTML, JSON, and other matched assets.


Supported algorithms are Brotli, Gzip, Deflate, and DeflateRaw. The default algorithm is Brotli.


<a id="requirements"></a>
## Requirements


This plugin requires Node.js v18.0.0+ and Farm v1.0.0+.


<a id="installation"></a>
## Installation


**npm**

```javascript
npm install @farmfe/plugin-compress
```


**yarn**

```javascript
yarn add @farmfe/plugin-compress
```


**pnpm**

```javascript
pnpm add @farmfe/plugin-compress
```



<a id="usage"></a>
## Usage


Register the plugin in ` farm.config.ts `:


```ts
import { defineConfig } from "@farmfe/core";
import compress from "@farmfe/plugin-compress";

export default defineConfig({
  plugins: [
    compress({
      algorithm: "brotli",
      threshold: 1024,
    }),
  ],
});
```


<a id="options"></a>
## Options


- ` algorithm?: "gzip" | "brotli" | "deflateRaw" | "deflate" ` — compression algorithm. Defaults to ` "brotli" `.
- ` level?: number ` — compression level. Defaults to ` 6 `.
- ` threshold?: number ` — minimum file size in bytes before compression. Defaults to ` 1024 `.
- ` filter?: string ` — regular expression string for resources to compress. Defaults to ` "\\.(js|mjs|json|css|html)$" `.
- ` deleteOriginFile?: boolean ` — delete the original uncompressed file after successful compression. Defaults to ` false `.



> [!NOTE]
> note
> 
> ` filter ` must be a string, not a ` RegExp ` object, because Rust plugin options are serialized through JSON before they are deserialized by the native plugin. Use a string pattern such as ` "\\.(js|css)$" ` instead of ` /\.(js|css)$/ `.
