Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .eslintrc

This file was deleted.

5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ jobs:
- name: Install pnpm
uses: pnpm/action-setup@v2

# Lint tooling only — the test matrix below still covers the Node 20
# runtime floor. `@antfu/eslint-config` (via eslint-plugin-unicorn)
# relies on `Set.prototype.union`, which needs Node 22.
- name: Set node
uses: actions/setup-node@v3
with:
node-version: 20.x
node-version: 24.x

- name: Setup
run: npm i -g @antfu/ni
Expand Down
24 changes: 16 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ Example using <a href="https://github.com/unjs/listhen">listhen</a> for an elega

```ts
import { createApp, eventHandler, toNodeListener } from 'h3'
import { listen } from 'listhen'
import { useCompressionStream } from 'h3-compression'
import { listen } from 'listhen'

const app = createApp({ onBeforeResponse: useCompressionStream }) // or { onBeforeResponse: useCompression }
app.use(
Expand Down Expand Up @@ -166,7 +166,9 @@ Branch on it yourself with the exported predicate:
```ts
import { isZstdSupported } from 'h3-compression'

app.use(compression({ zstd: isZstdSupported() }))
app.use(compression({
zstd: isZstdSupported()
}))
```

## Nuxt 3 & 4
Expand All @@ -192,7 +194,13 @@ export default defineNuxtConfig({
brotli: false, // stream path only — zlib always prefers brotli
zstd: false, // needs Node >= 22.15
method: undefined, // force one method instead of negotiating
contentTypes: ['text/', 'application/json', 'application/javascript', 'application/xml', 'image/svg+xml'],
contentTypes: [
'text/',
'application/json',
'application/javascript',
'application/xml',
'image/svg+xml'
],
exclude: ['/_nuxt', '/__nuxt'],
routeRules: true, // also compress cached (swr/isr) routes and /server/api
threshold: 0, // skip bodies smaller than this many bytes
Expand Down Expand Up @@ -259,7 +267,7 @@ before calling it.

H3-compression has a concept of composable utilities that accept `event` (from `eventHandler((event) => {})`) as their first argument and `response` as their second.

#### Zlib Compression
### Zlib Compression

- `useGZipCompression(event, response)`
- `useDeflateCompression(event, response)`
Expand All @@ -268,7 +276,7 @@ H3-compression has a concept of composable utilities that accept `event` (from `
- `useCompression(event, response, options?)` &nbsp;– pass `{ zstd: true }` to include zstd
- `compress(event, response, method?, options?)` &nbsp;– low-level helper; negotiates when `method` is omitted

#### Stream Compression
### Stream Compression

- `useGZipCompressionStream(event, response)`
- `useDeflateCompressionStream(event, response)`
Expand All @@ -277,23 +285,23 @@ H3-compression has a concept of composable utilities that accept `event` (from `
- `useCompressionStream(event, response, options?)` &nbsp;– pass `{ brotli: true }` / `{ zstd: true }`
- `compressStream(event, response, method?, options?)` &nbsp;– low-level helper; negotiates when `method` is omitted

#### Middleware (h3 v2)
### Middleware (h3 v2)

- `compression(method | options?)` &nbsp;– middleware using zlib (brotli, gzip, deflate, opt-in zstd)
- `compressionStream(method | options?)` &nbsp;– stream middleware (gzip, deflate, opt-in brotli / zstd)
- `compressResponse(event, value, method?, options?)` &nbsp;– low-level helper returning a compressed `Response`
- `compressResponseStream(event, value, method?, options?)` &nbsp;– low-level stream helper returning a compressed `Response`
- `isZstdSupported()` &nbsp;– whether the runtime can compress with zstd

#### Nuxt
### Nuxt

- `h3-compression/nuxt` &nbsp;– the Nuxt module, configured under the `compression` key

## Sponsors

<p align="center">
<a href="https://pinia-orm.codedredd.de/sponsorkit/sponsors.png">
<img src='https://pinia-orm.codedredd.de/sponsorkit/sponsors.svg'/>
<img src='https://pinia-orm.codedredd.de/sponsorkit/sponsors.svg' alt='Sponsors'/>
</a>
</p>

Expand Down
7 changes: 6 additions & 1 deletion build.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ export default defineBuildConfig({
declaration: true,
},
],
externals: ['@nuxt/kit', '@nuxt/schema', 'h3', 'h3-compression'],
externals: [
'@nuxt/kit',
'@nuxt/schema',
'h3',
'h3-compression',
],
declaration: true,
clean: true,
rollup: {
Expand Down
9 changes: 9 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import antfu from '@antfu/eslint-config'

export default antfu({}, {
rules: {
// The JSDoc in this repo documents the return type (`@returns { boolean }`)
// and describes the value in the summary above it.
'jsdoc/require-returns-description': 'off',
},
})
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@
}
},
"files": [
"dist",
"LICENSE",
"README.md"
"README.md",
"dist"
],
"engines": {
"node": ">=20.11.1"
Expand All @@ -83,7 +83,7 @@
}
},
"devDependencies": {
"@antfu/eslint-config": "^0.41.0",
"@antfu/eslint-config": "^10.0.0",
"@antfu/ni": "^0.21.6",
"@antfu/utils": "^0.7.6",
"@nuxt/kit": "^3.13.0",
Expand All @@ -92,7 +92,7 @@
"@types/supertest": "^2.0.12",
"@vitest/coverage-v8": "^0.34.3",
"bumpp": "^9.2.0",
"eslint": "^8.48.0",
"eslint": "^10.15.0",
"esno": "^0.17.0",
"h3": "2.0.8",
"lint-staged": "^14.0.1",
Expand Down
Loading
Loading