When to use this API
Use the Integration API when you need to:- Add support for UI frameworks (React, Vue, Svelte, etc.)
- Inject routes, scripts, or styles into every page
- Add middleware to intercept requests
- Modify the Vite or Astro configuration
- Hook into the build process
- Add custom dev toolbar apps
- Extend TypeScript types in user projects
Creating an integration
An integration is an object with aname and hooks property:
Lifecycle hooks
Integrations execute during specific lifecycle events. All hooks receive alogger option for writing logs.
astro:config:setup
Runs on initialization before Vite or Astro config have resolved. Use this to extend the project configuration.Read-only copy of the user-supplied Astro config, resolved before other integrations run.
The command being executed:
dev- Runningastro devbuild- Runningastro buildpreview- Runningastro previewsync- Runningastro sync
false when dev server starts, true when reload is triggered. Useful to detect when this function is called more than once.Callback function to update the Astro config. Config is merged with user config and other integration updates.
Adds a component framework renderer (React, Vue, Svelte, etc.).
Adds a file to watch. When changed, the dev server will reload.
Adds a custom client directive for use in
.astro files.Adds middleware to run on each request.
Adds a custom dev toolbar app.
Injects a JavaScript string onto every page.Stages:
head-inline- In<head>, not optimized by Vitebefore-hydration- Client-side, before hydration, optimized by Vitepage- In<script type="module">, bundled by Vitepage-ssr- In frontmatter, runs once on import
Injects routes into the project.
Creates and returns the path to
.astro/integrations/<integration-name>/.astro:config:done
Runs after Astro config has resolved and other integrations have run. Use this to read the final config.Final resolved Astro config after all integrations have run.
Makes the integration an adapter. See the Adapter API.
Injects TypeScript types into the user’s project.
The project’s build output type based on configuration.
astro:server:setup
Runs just after the Vite server is created in dev mode. Use this to add Vite middleware or enable content refresh.Mutable Vite dev server instance.
Object with callback functions to interact with the dev toolbar:
toolbar.on(event, callback)- Listen for toolbar eventstoolbar.send(event, payload)- Send messages to toolbartoolbar.onAppInitialized(appId, callback)- Run when app initializestoolbar.onAppToggled(appId, callback)- Run when app toggles
Triggers an update to the content layer during dev.
astro:server:start
Runs just after the server’slisten() event. Use this to intercept network requests.
The address, family, and port number from Node’s
server.address() method.astro:server:done
Runs just after the dev server closes. Use this to run cleanup events.astro:build:start
Runs afterastro:config:done, before the production build begins. Use this to set up global objects or clients.
astro:build:setup
Runs immediately before the build. This is your final chance to modify the Vite config.The Vite configuration used in the build.
Map of pages with their build data.
Whether this is the client or server build phase.
Updates the Vite config for the build.
astro:build:ssr
Runs after a production SSR build completes. Use this to access the SSR manifest and entry points.Serialized SSR manifest with routing information.
Map of emitted entry points with route data as key and file URL as value.
The middleware file path if middleware exists.
astro:build:generated
Runs after static build has finished generating routes and assets. Use this to access generated files before cleanup.URL path to the build output directory.
astro:build:done
Runs after production build (SSG or SSR) completes. Use this to access generated routes and assets.URL path to the build output directory.
List of all generated pages with their finalized paths.
Map of output file paths grouped by route pattern.