Astro Integrations add new functionality and behaviors for your project with only a few lines of code. You can write a custom integration yourself, use an official integration, or use integrations built by the community.
Integrations can…
Astro includes an astro add
command to automate the setup of integrations.
Run the astro add
command using the package manager of your choice and our automatic integration wizard will update your configuration file and install any necessary dependencies.
npx astro add react
pnpx astro add react
yarn astro add react
It’s even possible to configure multiple integrations at the same time!
npx astro add react tailwind partytown
pnpx astro add react tailwind partytown
yarn astro add react tailwind partytown
Astro integrations are always added through the integrations
property in your astro.config.mjs
file.
There are three common ways to import an integration into your Astro project:
import {defineConfig} from 'astro/config'; import installedIntegration from '@astrojs/vue'; import localIntegration from './my-integration.js'; export default defineConfig({ integrations: [ // 1. Imported from an installed npm package installedIntegration(), // 2. Imported from a local JS file localIntegration(), // 3. An inline object {name: 'namespace:id', hooks: { /* ... */ }}, ] })
Check out the Integration API reference to learn all of the different ways that you can write an integration.
Integrations are almost always authored as factory functions that return the actual integration object. This lets you pass arguments and options to the factory function that customize the integration for your project.
integrations: [ // Example: Customize your integration with function arguments sitemap({filter: true}) ]
Falsy integrations are ignored, so you can toggle integrations on & off without worrying about left-behind undefined
and boolean values.
integrations: [ // Example: Skip building a sitemap on Windows process.platform !== 'win32' && sitemap() ]
You can find many integrations developed by the community in the Astro Integrations Directory. Follow links there for detailed usage and configuration instructions.
Astro’s Integration API is inspired by Rollup and Vite, and designed to feel familiar to anyone who has ever written a Rollup or Vite plugin before.
Check out the Integration API reference to learn what integrations can do and how to write one yourself.
© 2021 Fred K. Schott
Licensed under the MIT License.
https://docs.astro.build/en/guides/integrations-guide/