0
0
AstroHow-ToBeginner ยท 3 min read

How to Use Adapter for Deployment in Astro

In Astro, use adapter packages to prepare your site for deployment on different platforms. Install the adapter for your target platform, then configure it in astro.config.mjs under the adapter property to enable platform-specific builds.
๐Ÿ“

Syntax

To use an adapter in Astro, you import the adapter package and add it to your astro.config.mjs file inside the adapter property. This tells Astro how to build and deploy your site for a specific platform.

Key parts:

  • import adapter from '@astrojs/adapter-name': imports the adapter package.
  • export default { adapter: adapter() }: sets the adapter in the config.
javascript
import adapter from '@astrojs/adapter-netlify';

export default {
  adapter: adapter(),
};
๐Ÿ’ป

Example

This example shows how to set up the Netlify adapter for deployment. It installs the adapter, imports it, and configures it in astro.config.mjs. When you run astro build, Astro prepares your site for Netlify hosting.

javascript
import adapter from '@astrojs/adapter-netlify';

export default {
  adapter: adapter(),
  // other config options can go here
};
Output
Build completed. Site ready for Netlify deployment.
โš ๏ธ

Common Pitfalls

Common mistakes when using adapters include:

  • Not installing the adapter package with npm install or yarn add.
  • Forgetting to import the adapter in astro.config.mjs.
  • Not calling the adapter as a function (adapter()), which is required.
  • Using an adapter that does not match your deployment platform.

Always check the adapter documentation for platform-specific options.

javascript
/* Wrong: adapter not called as function */
import adapter from '@astrojs/adapter-netlify';

export default {
  adapter: adapter, // โŒ should be adapter()
};

/* Correct: */
import adapter from '@astrojs/adapter-netlify';

export default {
  adapter: adapter(), // โœ…
};
๐Ÿ“Š

Quick Reference

StepDescription
Install adapterRun npm install @astrojs/adapter-name
Import adapterAdd import statement in astro.config.mjs
Configure adapterSet adapter: adapter() in export default
Build siteRun astro build to prepare for deployment
DeployUpload build output to your platform
โœ…

Key Takeaways

Install and import the correct adapter for your deployment platform.
Configure the adapter in astro.config.mjs by calling it as a function.
Adapters customize the build output for specific hosting environments.
Always run astro build after setting the adapter to prepare your site.
Check adapter docs for platform-specific options and updates.