Gatsby Local Development Guide

Build React static sites with Gatsby, utilizing a GraphQL data layer, and develop locally on the default localhost:8000.


Gatsby is a static site generator (SSG) based on React, which pulls data from various sources such as Markdown, CMS, and APIs through GraphQL, generating high-performance static pages suitable for blogs, marketing sites, and content aggregation sites.

Quick Start

npm init gatsby
cd my-gatsby-site
npm run develop

Or use the CLI:

npx gatsby new my-gatsby-site https://github.com/gatsbyjs/gatsby-starter-default
cd my-gatsby-site
npm run develop

Default localhost Access

PurposeAddress
Development Serverhttp://localhost:8000
GraphQL Explorerhttp://localhost:8000/___graphql
Preview Production Buildhttp://localhost:9000 (npm run serve)

To change the port: gatsby develop -p 8080.

Common Commands

CommandDescription
npm run developStart the development server
npm run buildGenerate static site in public/
npm run servePreview the production build
npm run cleanClear cache and build artifacts

Data and Plugins

  • Integrate file systems, WordPress, Contentful, etc., through gatsby-source-* plugins
  • Query data at the GraphQL layer during build time, with page components receiving props
  • A rich ecosystem of gatsby-plugin-* (image optimization, SEO, sitemap, etc.)

Summary

Gatsby local development defaults to http://localhost:8000. The GraphQL data layer is suitable for content-driven React static sites, which can be deployed to a CDN or Pages.

访客计数:------ Best viewed in Netscape Navigator · 800×600 © LocalHost Run