Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support domains option with Netlify Image CDN #1287

Merged
merged 2 commits into from
Mar 27, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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