移行

Gatsby から Astro への移行

要レビュー:その後Astroが新しいメジャーバージョンをリリース。

ライセンスと利用条件

Gatsby
MIT, オープンソース
Astro
Other, オープンソース
置き換えの度合い
完全な置き換え Ships HTML without JavaScript by default and renders React, Vue or Svelte components only where needed.

このページは英語で書かれています。

Compatibility

The official guide describes rebuilding the site in a new Astro project rather than converting it in place. Much carries over. .astro syntax is close to JSX, Markdown is built in and MDX comes through an integration, many existing Markdown plugins and npm dependencies keep working, and React components can be reused through the official React integration. Like Gatsby, Astro can produce a static site or render on the server, with prerendering per page.

Before you switch

  1. Create a project with npm create astro@latest, and copy the Gatsby files into a folder outside src. Add @astrojs/react to reuse React components and @astrojs/mdx for MDX files.
  2. Delete Gatsby’s public/ folder (its build output), and rename static/ to public/. Astro builds to dist/.
  3. Move components, pages and the rest into src/. Pages go in src/pages/, where routing follows the file path.
  4. Convert layouts first. Each Astro page needs its own <html>, <head> and <body>, so a shared layout carries them, with <slot /> in place of {children}. Global CSS is imported in that layout instead of gatsby-browser.js.
  5. Convert each .js page to an .astro page: keep only the return() as the template, move imports and logic into the --- code fence, and read props from Astro.props. JSX page files cannot be used as pages.
  6. Replace GraphQL queries with import.meta.glob(), or with getCollection() and getEntry() if you use content collections.
  7. Repurpose the gatsby-*.js files: siteMetadata from gatsby-config.js goes into a data file such as src/data/siteMetadata.js, and an SSR setup from gatsby-ssr.js becomes an adapter in astro.config.mjs.

Pitfalls

公式ガイド

Astroの移行ガイド ↗

2026-09-29にレビュー済み。

出典

Gatsbyのその他の代替 →