definePlugin
Allows defining a type-safe plugin that can be used in defineIntegration
.
You can then use it in withPlugins
:
Usage
-
A plugin defines a
name
and asetup
function. -
The
setup
function accepts a name and must return an object -
The returned object is made of astro hooks and must returned an object of additional properties
defineAllHooksPlugin
defineAllHooksPlugin
is a variation of definePlugin
for when you want to provide the same API for every hook defined in the consumer integration.
Using this function has an advantange because it allows your plugin to provide an API even for hooks it doesn’t know about, like any Astro hook added after the plugin release or hooks added by integrations like @astrojs/db
.
Instead of providing a setup
function returning a map of your API factory for each hook, you provide a function that receives a hook name and returns the API factory for that hook.
Limitations
- Plugins support overrides. That means that if 2 plugins declare the same
name
, the latest will be kept.
Practical examples
Astro Integration Kit uses definePlugin
for its core plugins under the hood,
have a look at our source for practical examples!