astro/.changeset/cold-schools-yell.md
Matthew Phillips 2167ffd72f
Revert "[ci] release (#8671)" (#8696)
This reverts commit eada8ab8fa.
2023-09-28 13:57:54 -04:00

1.1 KiB
Raw Blame History

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:

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 */ }],
        });
      }
    },
  };
};