Skip to content

Commit 32965d5

Browse files
committed
chore: use http-client-hints
1 parent acde42f commit 32965d5

24 files changed

+46
-987
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ or in your modules, composables, or other plugins:
101101
const clientHints = useNuxtApp().$httpClientHints
102102
```
103103

104+
You can also use this module with [HTTP Client Hints for H3](https://github.com/userquin/http-client-hints/blob/main/src/h3.ts) (`http-client-hints/h3`) to add a custom [Nitro](https://github.com/unjs/nitro) image event handler to send back to the browser an optimized image from the original one. Check the [playground](https://github.com/userquin/nuxt-http-client-hints/tree/main/playground/server) server folder for an example using Nitro server handler in dev and production mode with [sharp](https://github.com/lovell/sharp).
105+
104106
That's it! You can now use HTTP Client Hints in your Nuxt app ✨
105107

106108
You can check the source code or the [JSDocs](https://www.jsdocs.io/package/nuxt-http-client-hints) for more information.

eslint.config.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export default createConfigForNuxt({
1515
],
1616
},
1717
})
18-
.append(
18+
.append([{
19+
ignores: ['server-utils.d.ts'],
20+
}],
1921
// your custom flat config here...
2022
)

package.json

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "nuxt-http-client-hints",
33
"type": "module",
44
"version": "0.0.2",
5-
"packageManager": "[email protected].1",
5+
"packageManager": "[email protected].3",
66
"description": "Nuxt HTTP Client Hints",
77
"author": "userquin <[email protected]>",
88
"license": "MIT",
@@ -25,19 +25,10 @@
2525
"types": "./dist/types.d.mts",
2626
"default": "./dist/module.mjs"
2727
},
28-
"./server-utils": {
29-
"types": "./dist/runtime/server/utils.d.ts",
30-
"default": "./dist/runtime/server/utils.js"
31-
},
3228
"./package.json": "./package.json"
3329
},
3430
"main": "./dist/module.mjs",
3531
"types": "./dist/types.d.ts",
36-
"typesVersions": {
37-
"*": {
38-
"server-utils": ["./dist/runtime/server/utils.d.ts"]
39-
}
40-
},
4132
"files": [
4233
"dist"
4334
],
@@ -53,7 +44,8 @@
5344
"test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit"
5445
},
5546
"dependencies": {
56-
"detect-browser-es": "^0.1.1"
47+
"detect-browser-es": "^0.1.1",
48+
"http-client-hints": "^0.0.1"
5749
},
5850
"devDependencies": {
5951
"@nuxt/kit": "^3.13.2",

playground/server/dev-image.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { Readable } from 'node:stream'
44
import { lazyEventHandler, eventHandler, sendStream } from 'h3'
55
import sharp from 'sharp'
66
import { useNitro } from '@nuxt/kit'
7-
import { extractImageClientHints } from '../../src/runtime/server/utils'
8-
import type { ResolvedHttpClientHintsOptions, ServerHttpClientHintsOptions } from '../../src/runtime/server/utils'
7+
import { extractImageClientHints } from 'http-client-hints/h3'
8+
import type { ResolvedHttpClientHintsOptions, ServerHttpClientHintsOptions } from 'http-client-hints/h3'
99

1010
export default lazyEventHandler(async () => {
1111
const nitroOptions = useNitro().options

playground/server/image.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { Readable } from 'node:stream'
44
import { fileURLToPath } from 'node:url'
55
import { lazyEventHandler, eventHandler, sendStream } from 'h3'
66
import sharp from 'sharp'
7-
import { extractImageClientHints } from '../../src/runtime/server/utils'
8-
import type { ResolvedHttpClientHintsOptions, ServerHttpClientHintsOptions } from '../../src/runtime/server/utils'
7+
import { extractImageClientHints } from 'http-client-hints/h3'
8+
import type { ResolvedHttpClientHintsOptions, ServerHttpClientHintsOptions } from 'http-client-hints/h3'
99
// import { readAsset } from '#internal/nitro/virtual/public-assets-data'
1010

1111
export default lazyEventHandler(() => {

pnpm-lock.yaml

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { createResolver, defineNuxtModule, useLogger } from '@nuxt/kit'
22
import type { HookResult } from '@nuxt/schema'
3+
import type { HttpClientHintsState } from 'http-client-hints'
34
import { version } from '../package.json'
45
import type { HttpClientHintsOptions as ModuleOptions } from './types'
56
import { configure } from './utils/configuration'
6-
import type { HttpClientHintsState } from './runtime/shared-types/types'
77

88
export type { ModuleOptions }
99

src/runtime/plugins/critical.server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { parseUserAgent } from 'detect-browser-es'
2-
import { CriticalHintsHeaders, extractCriticalHints } from '../utils/critical'
3-
import type { ResolvedHttpClientHintsOptions } from '../shared-types/types'
2+
import { CriticalHintsHeaders, extractCriticalHints } from 'http-client-hints/critical'
3+
import type { ResolvedHttpClientHintsOptions } from 'http-client-hints'
44
import { writeHeaders } from './headers'
55
import { useHttpClientHintsState } from './utils'
66
import { defineNuxtPlugin, useCookie, useRequestHeaders } from '#imports'

src/runtime/plugins/detect.client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { browserName, detect, asyncDetect, detectOS, parseUserAgent } from 'detect-browser-es'
2-
import type { UserAgentHints } from '../shared-types/types'
2+
import type { UserAgentHints } from 'http-client-hints'
33
import { defineNuxtPlugin } from '#imports'
44
import type { Plugin } from '#app'
55

src/runtime/plugins/detect.server.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import {
66
parseUserAgent,
77
} from 'detect-browser-es'
88
import { appendHeader } from 'h3'
9-
import type { ResolvedHttpClientHintsOptions, UserAgentHints } from '../shared-types/types'
10-
import { extractBrowser } from '../utils/detect'
9+
import type { ResolvedHttpClientHintsOptions, UserAgentHints } from 'http-client-hints'
10+
import { extractBrowserHints } from 'http-client-hints/detect'
1111
import { useHttpClientHintsState } from './utils'
1212
import {
1313
defineNuxtPlugin,
@@ -30,7 +30,7 @@ const plugin: Plugin = defineNuxtPlugin({
3030

3131
const userAgentHeader = requestHeaders['user-agent']
3232

33-
const browser = await extractBrowser(
33+
const browser = await extractBrowserHints(
3434
httpClientHints,
3535
requestHeaders,
3636
userAgentHeader,

0 commit comments

Comments
 (0)