Usage
Astro Integration Kit can be used in 2 ways: as extended hooks or as standalone utilities.
Which flavor should you use?
Extended hooks provide a way better DX and we recommend picking this one by default. However, if you have
an existing integration that you want to migrate to astro-integration-kit
, using standalone utilities
will allow you to migrate progressively. Any standalone utility is also available as an extended hook
argument.
Extended hooks
Plugins
Astro Integration Kit is built in a modular way. By default, it brings a solid foundation
that makes it easily extendable by plugins. By default, no plugin is enabled but the package ships
with some corePlugins
(documented on this website), that you can easily enable, either all at once
or one by one as needed.
import { defineIntegration } from "astro-integration-kit";import { corePlugins } from "astro-integration-kit/plugins";
export default defineIntegration({ name: "my-integration", plugins: [...corePlugins], setup() { return { "astro:config:setup": ({ addDts }) => {} } }})
import { defineIntegration } from "astro-integration-kit";import { addDtsPlugin } from "astro-integration-kit/plugins";
export default defineIntegration({ name: "my-integration", plugins: [addDtsPlugin], setup() { return { "astro:config:setup": ({ addDts }) => {} } }})
This allows other developers to easily add their own plugins.
Defining an integration
To define your integration, use the defineIntegration
utility:
import { createResolver, defineIntegration } from "astro-integration-kit";import { corePlugins } from "astro-integration-kit/plugins"
export default defineIntegration({ name: "my-integration", plugins: [...corePlugins], setup() { const { resolve } = createResolver(import.meta.url); return { "astro:config:setup": ({ watchIntegration }) => { watchIntegration(resolve()) } } }})
Standalone utilities
Use utilities exported from astro-integration-kit/utilities
:
import type { AstroIntegration } from "astro";import { createResolver } from "astro-integration-kit";import { watchIntegration } from "astro-integration-kit/utilities";
export default function myIntegration(): AstroIntegration { const { resolve } = createResolver(import.meta.url); return { name: "my-integration", hooks: { "astro:config:setup": ({ addWatchFile, command, updateConfig }) => { watchIntegration({ addWatchFile, command, dir: resolve(), updateConfig, }); }, } }}