Skip to content

Usage

Astro Integration Kit provides a suite of useful utilities to help you build your integrations. Some of them are “global” (eg. defineIntegration), others are meant to be used in hooks (eg. addDts) and plugins are available for more advanced usecases (eg. hasVitePluginPlugin). Each utility is fully documented with examples and options!

Here we are using the addDts utility to add a TypeScript declaration file to the user’s project! This is useful for typing things like Virtual Modules!

my-integration/index.ts
1
import { defineIntegration, addDts } from "astro-integration-kit"
2
import { z } from "astro/zod"
3
4
export default defineIntegration({
5
name: "my-integration",
6
optionsSchema: z.object({
7
virtualModuleId: z.string()
8
}),
9
setup({ options, name }) {
10
return {
11
hooks: {
12
"astro:config:setup": (params) => {
13
addDts(params, {
14
name,
15
content: `declare module ${JSON.stringify(options.virtualModuleId)} {}`
16
})
17
}
18
}
19
}
20
}
21
})