Skip to content

Commit

Permalink
feat(vercel): set image config using v3 output api
Browse files Browse the repository at this point in the history
(requires nitro 0.5.2+)
  • Loading branch information
pi0 committed Sep 13, 2022
1 parent 4c23770 commit 4d8aab0
Show file tree
Hide file tree
Showing 3 changed files with 226 additions and 204 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ dist/
coverage
sw.*
.vscode
.vercel_build_output
.vercel
.output
23 changes: 14 additions & 9 deletions src/provider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { promises as fsp } from 'fs'
import { normalize, resolve, dirname } from 'pathe'
import { normalize } from 'pathe'
import { defu } from 'defu'
import type { Nuxt } from '@nuxt/schema'
import { createResolver, resolvePath } from '@nuxt/kit'
import { hash } from 'ohash'
import type { InputProvider, ImageModuleProvider, ProviderSetup } from './types'
Expand Down Expand Up @@ -35,13 +36,17 @@ export const providerSetup: Record<string, ProviderSetup> = {
static: ipxSetup,

// https://vercel.com/docs/more/adding-your-framework#images
async vercel (_providerOptions, moduleOptions, nuxt) {
const imagesConfig = resolve(nuxt.options.rootDir, '.vercel_build_output/config/images.json')
await fsp.mkdir(dirname(imagesConfig), { recursive: true })
await fsp.writeFile(imagesConfig, JSON.stringify({
domains: moduleOptions.domains,
sizes: Array.from(new Set(Object.values(moduleOptions.screens || {})))
}, null, 2))
vercel (_providerOptions, moduleOptions, nuxt: Nuxt) {
nuxt.options.nitro = defu(nuxt.options.nitro, {
vercel: {
config: {
image: {
domains: moduleOptions.domains,
sizes: Array.from(new Set(Object.values(moduleOptions.screens || {})))
}
}
}
})
}
}

Expand Down
Loading

0 comments on commit 4d8aab0

Please sign in to comment.