Skip to content
Draft
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
2 changes: 1 addition & 1 deletion .nuxtrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
setups.@nuxt/test-utils="4.0.0"
setups.@nuxt/test-utils="4.0.3"
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
},
"dependencies": {
"@nuxt/image": "latest",
"nuxt": "4.4.8"
"nuxt": "npm:nuxt-nightly@5.0.0-29738334.1405742f"
}
}
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@
"test:built:types": "nuxt typecheck playground && nuxt typecheck example"
},
"dependencies": {
"@nuxt/kit": "^4.4.8",
"@nuxt/kit": "npm:@nuxt/kit-nightly@5.0.0-29738334.1405742f",
"consola": "^3.4.2",
"defu": "^6.1.7",
"h3": "^1.15.11",
"h3": "^2.0.1-rc.22",
"image-meta": "^0.2.2",
"knitwork": "^1.3.0",
"ohash": "^2.0.11",
Expand All @@ -60,7 +60,7 @@
"devDependencies": {
"@nuxt/eslint-config": "1.16.0",
"@nuxt/module-builder": "1.0.2",
"@nuxt/schema": "4.4.8",
"@nuxt/schema": "npm:@nuxt/schema-nightly@5.0.0-29738334.1405742f",
"@nuxt/test-utils": "^4.0.3",
"@types/node": "^24.13.2",
"@types/semver": "^7.7.1",
Expand All @@ -74,8 +74,8 @@
"ipx": "^3.1.1",
"jiti": "2.7.0",
"knip": "^6.16.1",
"nitropack": "^2.13.4",
"nuxt": "^4.4.8",
"nitro": "^3.0.260610-beta",
"nuxt": "npm:nuxt-nightly@5.0.0-29738334.1405742f",
"ofetch": "^1.5.1",
"pkg-pr-new": "^0.0.75",
"playwright-core": "^1.60.0",
Expand Down
2 changes: 1 addition & 1 deletion playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
},
"devDependencies": {
"@nuxt/image": "latest",
"nuxt": "4.4.8"
"nuxt": "npm:nuxt-nightly@5.0.0-29738334.1405742f"
}
}
2 changes: 2 additions & 0 deletions playground/server/api/image.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { defineEventHandler } from 'h3'

export default defineEventHandler(async (event) => {
const image = useImage(event)
return image.getImage('/image.jpg', {
Expand Down
4,692 changes: 3,396 additions & 1,296 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ verifyDepsBeforeRun: install

overrides:
"@nuxt/image": "workspace:*"
"@nuxt/schema": "4.4.8"
"@types/node": "^24.13.2"
vue: "3.5.38"

Expand All @@ -18,3 +17,10 @@ allowBuilds:
sharp: true
unrs-resolver: false
vue-demi: false

minimumReleaseAgeExclude:
- '@nuxt/kit-nightly@5.0.0-29738334.1405742f'
- '@nuxt/nitro-server-nightly@5.0.0-29738334.1405742f'
- '@nuxt/schema-nightly@5.0.0-29738334.1405742f'
- '@nuxt/vite-builder-nightly@5.0.0-29738334.1405742f'
- nuxt-nightly@5.0.0-29738334.1405742f
9 changes: 4 additions & 5 deletions src/ipx.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { arch, platform } from 'node:os'
import { readdir } from 'node:fs/promises'
import { join, relative } from 'pathe'
import { join } from 'pathe'
import { useNuxt, createResolver, useNitro, useLogger } from '@nuxt/kit'
import type { NitroEventHandler } from 'nitropack'
import type { NitroEventHandler } from 'nitro/types'
import { defu } from 'defu'
import { hasProtocol } from 'ufo'
import type { ProviderSetup } from './types'
Expand All @@ -27,7 +27,6 @@ export const ipxSetup: IPXSetupT = setupOptions => (providerOptions, moduleOptio
}

// Options
const relativeDir = relative(nitro.options.output.serverDir, nitro.options.output.publicDir)
const ipxOptions: IPXRuntimeConfig = {
...providerOptions.options,
baseURL: ipxBaseURL,
Expand All @@ -36,7 +35,7 @@ export const ipxSetup: IPXSetupT = setupOptions => (providerOptions, moduleOptio
...providerOptions.options?.alias,
},
fs: (providerOptions.options?.fs !== false) && {
dir: nuxt.options.dev ? moduleOptions.dirs : relativeDir,
dir: nuxt.options.dev ? moduleOptions.dirs : nitro.options.output.publicDir,
...providerOptions.options?.fs,
},
http: (providerOptions.options?.http !== false) && {
Expand Down Expand Up @@ -80,7 +79,7 @@ export const ipxSetup: IPXSetupT = setupOptions => (providerOptions, moduleOptio
}
}

declare module 'nitropack' {
declare module 'nitro/types' {
interface NitroRuntimeConfig {
ipx?: IPXRuntimeConfig
}
Expand Down
3 changes: 2 additions & 1 deletion src/provider.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { normalize } from 'pathe'
import { defu } from 'defu'
import type { Nuxt } from '@nuxt/schema'
import type { NitroConfig } from 'nitropack'
import type { NitroConfig } from 'nitro/types'
import { createResolver, resolvePath } from '@nuxt/kit'
import { hash } from 'ohash'
import { genSafeVariableName } from 'knitwork'
Expand Down Expand Up @@ -91,6 +91,7 @@ const providerSetup: Partial<Record<ImageProviderName, ProviderSetup>> = {
nuxt.options.nitro = defu(nuxt.options.nitro, {
vercel: {
config: {
version: 3,
images: {
domains: moduleOptions.domains,
minimumCacheTTL: 60 * 5,
Expand Down
5 changes: 2 additions & 3 deletions src/runtime/providers/aliyun.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { joinURL, encodePath } from 'ufo'
import { createOperationsGenerator } from '../utils/index'
import { defineProvider } from '../utils/provider'
import { useRuntimeConfig } from '#imports'

const operationsGenerator = createOperationsGenerator({
joinWith: '/',
Expand Down Expand Up @@ -34,10 +33,10 @@ function getResizeValue(height?: number, width?: number) {
}

export default defineProvider<AliyunOptions>({
getImage: (src, { modifiers, baseURL }) => {
getImage: (src, { modifiers, baseURL }, ctx) => {
if (!baseURL) {
// also support runtime config
baseURL = useRuntimeConfig().public.siteUrl as string | undefined || '/'
baseURL = ctx.options.runtimeConfig.public.siteUrl as string | undefined || '/'
}
const _modifiers = { ...modifiers }
const { resize, width, height, quality } = _modifiers
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/providers/awsAmplify.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { encodeQueryItem, joinURL } from 'ufo'
import type { NitroConfig } from 'nitropack'
import type { NitroConfig } from 'nitro/types'
import { createOperationsGenerator } from '../utils/index'
import { defineProvider } from '../utils/provider'

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/providers/vercel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { stringifyQuery } from 'ufo'
import type { NitroConfig } from 'nitropack'
import type { NitroConfig } from 'nitro/types'
import { defineProvider } from '../utils/provider'

// https://vercel.com/docs/build-output-api/v3/configuration#images
Expand Down
10 changes: 4 additions & 6 deletions src/runtime/providers/weserv.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { withBase } from 'ufo'
import { createOperationsGenerator } from '../utils/index'
import { defineProvider } from '../utils/provider'
import { createError } from '#imports'
import { HTTPError } from 'h3'

const operationsGenerator = createOperationsGenerator({
keyMap: {
Expand Down Expand Up @@ -100,17 +100,15 @@ export default defineProvider<WeservOptions>({

if (typeof options.baseURL !== 'string' || options.baseURL.length === 0) {
if (import.meta.dev) {
throw createError({
statusCode: 500,
statusMessage: 'Internal Server Error',
throw new HTTPError({
status: 500,
statusText: 'Internal Server Error',
message: 'The weserv provider requires the baseURL of your website.',
data: {
provider: 'weserv',
src,
modifiers: options.modifiers,
},
fatal: true,
name: 'NuxtImageError',
})
}
else {
Expand Down
8 changes: 4 additions & 4 deletions src/runtime/server/routes/_ipx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { fileURLToPath } from 'node:url'

import { createIPX, createIPXH3Handler, ipxFSStorage, ipxHttpStorage } from 'ipx'
import type { IPXOptions } from 'ipx'
import { lazyEventHandler, useBase } from 'h3'
import { lazyEventHandler, withBase } from 'h3'
import { isAbsolute } from 'pathe'
import type { NitroRuntimeConfig } from 'nitropack'
import type { NitroRuntimeConfig } from 'nitro/types'

import { useRuntimeConfig } from '#imports'
import { useRuntimeConfig } from 'nitro/runtime-config'

export default lazyEventHandler(() => {
const opts = useRuntimeConfig().ipx as NitroRuntimeConfig['ipx'] || {} as Record<string, never>
Expand All @@ -29,5 +29,5 @@ export default lazyEventHandler(() => {
const ipx = createIPX(ipxOptions)

const ipxHandler = createIPXH3Handler(ipx)
return useBase(opts.baseURL, ipxHandler)
return withBase(opts.baseURL, ipxHandler)
})
2 changes: 1 addition & 1 deletion src/runtime/server/utils/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Img } from '@nuxt/image'

// @ts-expect-error virtual file
import { imageOptions } from '#internal/nuxt-image'
import { useRuntimeConfig } from '#imports'
import { useRuntimeConfig } from 'nitro/runtime-config'

export const useImage = (event?: H3Event): Img => {
const config = useRuntimeConfig()
Expand Down
3 changes: 1 addition & 2 deletions src/runtime/utils/prerender.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { H3Event } from 'h3'
import { appendHeader } from 'h3'

export function prerenderStaticImages(src = '', srcset = '', event?: H3Event) {
if (!import.meta.server || !import.meta.prerender || !event) {
Expand All @@ -15,5 +14,5 @@ export function prerenderStaticImages(src = '', srcset = '', event?: H3Event) {
return
}

appendHeader(event, 'x-nitro-prerender', paths.map(p => encodeURIComponent(p)).join(', '))
event.res.headers.append('x-nitro-prerender', paths.map(p => encodeURIComponent(p)).join(', '))
}
Loading