How to build and deploy a static site with Astro 7.4
Use Astro 7.4 to build a static site: pin Node, add a page and component, hydrate one React island, query a Markdown collection, and deploy the output.
This tutorial builds a small static site with Astro 7.4. You will pin the Astro version, create a page and reusable component, add one interactive React island, load a Markdown entry through a content collection, and publish the production output from `dist/`.
How to build and deploy a static site with Astro 7.4
We’ll build a small static site from an empty Astro project. The examples target Astro 7.4.0 and Node.js 22.22.0 or newer. Astro 7.4 raised its minimum Node.js 22 version to 22.22.0; check the Astro 7.4 release notes if your local version is older.
The examples use the current Astro content layer API: src/content.config.ts, glob() from astro/loaders, and a schema. Astro is pinned to 7.4.0; the official documentation links below were checked on 2026-11-03.
1. Create and pin the project
Check Node first:
node --version
Use Node.js 22.22.0 or later in the supported Node 22 line. Then run Astro’s project wizard and choose an empty or minimal starter:
npm create astro@latest astro-static-demo
cd astro-static-demo
npm install --save-exact astro@7.4.0
The install writes Astro’s exact version to package.json, without a version range. Verify it:
npm ls astro
npx astro --version
Check that npm lists astro@7.4.0 and the version command reports 7.4.0. Keep the generated package-lock.json with the project so later installs resolve the same dependency tree. The Astro installation guide documents the project wizard.
2. Add a page and reusable component
Astro pages and components use .astro files. They render to HTML at build time for this static project. Create src/pages/index.astro:
---
---
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>Tiny Astro Site</title>
</head>
<body>
<header>
<a href="/">Tiny Astro Site</a>
</header>
<main>
<h1>A small page, built with Astro</h1>
<p>This route is generated as HTML during the production build.</p>
</main>
</body>
</html>
Start the dev server:
npm run dev
Open the local URL printed by Astro, usually http://localhost:4321/. You should see the heading and paragraph. Stop the server with Ctrl+C before continuing.
Now move the header into src/components/SiteHeader.astro so it can be reused:
---
interface Props {
title: string;
}
const { title } = Astro.props;
---
<header>
<a href="/">{title}</a>
</header>
Import it from a page with import SiteHeader from '../components/SiteHeader.astro';, then render it as <SiteHeader title="Tiny Astro Site" />. Astro components have no client-side runtime by default; see the Astro components guide.
3. Add one interactive React island
Install Astro’s official React integration and accept its setup changes:
npx astro add react
The command adds the integration and its React dependencies, then updates the Astro configuration. The React integration guide has the manual setup if the command cannot apply those changes.
Create src/components/Counter.jsx:
import { useState } from "react";
export default function Counter() {
const [count, setCount] = useState(0);
return (
<button type="button" onClick={() => setCount((value) => value + 1)}>
Clicks: {count}
</button>
);
}
We will place this component in the page with client:load. That directive asks Astro to hydrate this React component in the browser as the page loads. Astro still renders the header, text, and post list as HTML; React runs only for the counter. This is the island boundary described in Astro’s islands guide.
4. Load and list a Markdown entry
Create src/content.config.ts to register a build-time collection. The schema checks the frontmatter fields this example uses:
import { defineCollection } from "astro:content";
import { glob } from "astro/loaders";
import { z } from "astro/zod";
const posts = defineCollection({
loader: glob({ base: "./src/content/posts", pattern: "**/*.md" }),
schema: z.object({
title: z.string(),
description: z.string(),
}),
});
export const collections = { posts };
Add one entry at src/content/posts/first-post.md:
---
title: "My first post"
description: "A note stored as Markdown and checked against the posts schema."
---
This entry is read when Astro builds the site.
Replace src/pages/index.astro with the final page below. It queries the collection and lists its entry; it also uses the reusable header and React counter from the previous steps.
---
import { getCollection } from "astro:content";
import Counter from "../components/Counter.jsx";
import SiteHeader from "../components/SiteHeader.astro";
const posts = await getCollection("posts");
---
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>Tiny Astro Site</title>
</head>
<body>
<SiteHeader title="Tiny Astro Site" />
<main>
<h1>A small page, built with Astro</h1>
<p>This route is generated as HTML during the production build.</p>
<h2>Try the counter</h2>
<Counter client:load />
<h2>Posts</h2>
<ul>
{posts.map((post) => <li>{post.data.title}</li>)}
</ul>
</main>
</body>
</html>
Start the dev server again. The page should show My first post, and clicking the counter button should increase its number. If the frontmatter misses a required field, Astro reports a schema validation error. The content collections guide covers querying, rendering, and routing entries.
For a closer look at React state, see React state with useState. For accessible controls and labels, see accessible React interfaces.
5. Build and inspect the static output
Create the production build:
npm run build
Astro should finish without a schema or compilation error and write the site to dist/. Check that dist/index.html exists and that dist/_astro/ contains the generated assets, including the counter’s client bundle. The page itself is static HTML.
You can serve the build locally before deployment:
npm run preview
Open the URL Astro prints and check the rendered page and counter. A development server is useful while editing; this preview lets you inspect the built output.
6. Deploy dist/ to a static host
For a host that builds from your repository, set the build command to npm run build and the publish directory to dist. If the host expects a locally built site, upload the contents of dist/ while preserving its directory structure. dist/index.html is the home page, and the generated assets under dist/_astro/ must be uploaded with it. The Astro deployment guide lists the build command and output directory used by common hosts.
This static output needs no server adapter. If you later add request-time rendering, choose a host and adapter that support it.
Conclusion
At this point, npm run build produces a deployable static site in dist/: a page, one reusable .astro component, one hydrated React counter, and a Markdown-backed post list.
Category
Related Posts
Capstone: Build a Typed React Task Tracker
Build a React task tracker with typed filters, accessible forms, versioned local storage, migration recovery, and a behavior test.
GitHub Actions release pipeline with a production gate
Build and test a static site with GitHub Actions, then require a production approval before GitHub Pages deploys the build artifact.
React + TypeScript Fundamentals Roadmap
Learn React and TypeScript through accessible, tested interfaces, from JSX and typed components to state, forms, effects, and a complete project.