Skip to content

Commit

Permalink
feat: support domains option with Netlify Image CDN
Browse files Browse the repository at this point in the history
  • Loading branch information
ascorbic committed Mar 15, 2024
1 parent 1490f0e commit 97f96d6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
14 changes: 8 additions & 6 deletions docs/content/3.providers/netlify.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@ To test image transformations locally, use [Netlify Dev](https://docs.netlify.co

## Remote images

To transform a source image hosted on another domain, you must first configure allowed domains in your `netlify.toml` file.
To transform a source image hosted on another domain, you must first configure allowed domains:

```toml [netlify.toml]
[images]
remote_images = ["https://my-images.com/.*", "https://animals.more-images.com/[bcr]at/.*"]
```ts [nuxt.config.ts]
export default defineNuxtConfig({
image: {
provider: 'netlify',
domains: ['images.example.com']
}
})
```

The `remote_images` property accepts an array of regex. If your images are in specific subdomains or directories, you can use regex to allow just those subdomains or directories.

## Modifiers

Beyond the [standard properties](https://image.nuxt.com/usage/nuxt-img), you can use the [Netlify Image CDN `position` parameter](https://docs.netlify.com/image-cdn/overview/#position) as a modifier for Nuxt Image.
Expand Down
12 changes: 12 additions & 0 deletions src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ export const providerSetup: Partial<Record<ImageProviderName, ProviderSetup>> =
}
}
})
},
// https://docs.netlify.com/image-cdn/create-integration/
netlify (_providerOptions, moduleOptions, nuxt: Nuxt) {
if (moduleOptions.domains?.length > 0) {
nuxt.options.nitro = defu(nuxt.options.nitro, {
netlify: {
images: {
remote_images: moduleOptions.domains.map(domain => `https?:\\/\\/${domain.replaceAll('.', '\\.')}\\/.*`)
}
}
})
}
}
}

Expand Down

0 comments on commit 97f96d6

Please sign in to comment.