defineIntegration
defineIntegration
is a powerful wrapper around the standard Astro Integrations API. It allows to provide
extra hooks, functionality and best-practices when creating Astro Integrations.
Defining an integration
To define an integration, use the defineIntegration
utility:
It accepts a few arguments, whose usage is explained in the sections below.
Handling options and defaults
defineIntegration
accepts an optionsSchema
argument that is a zod
schema.
This way, you can:
- Add proper documentation using JSDoc annotations
- Provide defaults
- Well, take full advantage of
zod
’s power!
Using plugins
Plugins allow us (and you!) to make Astro Integration Kit really powerful. It allows to add arguments
to built-in hooks in a type-safe way. Get started by using our corePlugins
:
Under the hood, those plugins define using definePlugin
pass “metadata” as types thanks to generics.
Adding the logic with setup
If you’ve written an integration before by returning an AstroIntegration
from a function, it’s exactly
the same with setup
! This is where all the logic lives:
It accepts an object with data from the integration definition:
In setup, you’ll want to add any logic that is shared between any hook, for example:
- Calling
createResolver
- Save the
config
fromastro:config:done
to be used in later hooks
It needs to return Astro hooks.