astro/.changeset/cold-schools-yell.md
Chris Swithinbank 9b0114c7d3
Support integrations added in updateConfig() in astro:config:setup (#8672)
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
2023-09-27 21:17:27 +02:00

34 lines
1.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
'astro': minor
---
Support adding integrations dynamically
Astro integrations can now themselves dynamically add and configure additional integrations during set-up. This makes it possible for integration authors to bundle integrations more intelligently for their users.
In the following example, a custom integration checks whether `@astrojs/sitemap` is already configured. If not, the integration adds Astros sitemap integration, passing any desired configuration options:
```ts
import sitemap from '@astrojs/sitemap';
import type { AstroIntegration } from 'astro';
const MyIntegration = (): AstroIntegration => {
return {
name: 'my-integration',
'astro:config:setup': ({ config, updateConfig }) => {
// Look for sitemap in user-configured integrations.
const userSitemap = config.integrations.find(
({ name }) => name === '@astrojs/sitemap'
);
if (!userSitemap) {
// If sitemap wasnt found, add it.
updateConfig({
integrations: [sitemap({ /* opts */ }],
});
}
},
};
};
```