withPlugins
withPlugins
allows to extend hooks with custom parameters. Useful for advanced use-cases.
1import { defineIntegration, withPlugins } from "astro-integration-kit";2import { hasVitePluginPlugin } from "astro-integration-kit/plugins";3
4export default defineIntegration({5 name: "my-integration",6 setup({ name }) {7 return withPlugins({8 name,9 plugins: [hasVitePluginPlugin],10 hooks: {11 "astro:config:setup": ({ hasVitePlugin }) => {}12 }13 })14 }15})
Defining extra integration fields
Any extra property (not name
, plugins
or hooks
) passed to withPlugins
are returned unchanged.
You can use this to define fields you might want to access from outside your integration while having access to it’s internal state.
1import { defineIntegration, withPlugins } from "astro-integration-kit";2
3export default defineIntegration({4 // ...5 setup() {6 let counter = 0;7 return withPlugins({8 hooks: {9 "astro:config:setup": ({ logger }) => {10 logger.info(`Counter: ${counter++}`);11 },12 },13 api: {14 get counter() {15 return counter;16 },17 increment() {18 counter++;19 },20 },21 });22 },23});