next 和 nuxt 是全栈应用框架,分别基于 React 和 Vue,支持服务端渲染(SSR)和静态生成(SSG)。gatsby 是专注于内容的 React 静态生成器,内置 GraphQL 数据层。hexo 是轻量级的 Node.js 博客生成器,适合纯内容站点。sapper 是 Svelte 的旧版框架,已停止维护,建议迁移至 SvelteKit。
在构建现代 Web 项目时,选择合适的工具链直接影响开发效率和长期维护成本。next、nuxt、gatsby、hexo 和 sapper 代表了不同的技术路线。本文将从架构定位、路由系统、数据获取和维护状态四个维度进行深度对比。
next 和 nuxt 是真正的全栈框架。
gatsby 是专注于内容的静态生成器。
hexo 是轻量级博客生成器。
sapper 是 Svelte 的旧版应用框架。
所有现代框架都采用基于文件的路由系统,但实现细节不同。
next 使用 pages 或 app 目录。
[id]。// next: pages/users/[id].js
export default function User({ id }) {
return <div>User {id}</div>;
}
nuxt 使用 pages 目录。
<!-- nuxt: pages/users/_id.vue -->
<template>
<div>User {{ $route.params.id }}</div>
</template>
gatsby 使用 src/pages 目录。
createPages API 或文件命名。// gatsby: src/pages/users/{id}.js
export default function User({ params }) {
return <div>User {params.id}</div>;
}
sapper 使用 src/routes 目录。
<!-- sapper: src/routes/users/[id].svelte -->
<script>
export let id;
</script>
<div>User {id}</div>
hexo 不使用应用式路由。
_config.yml 配置 permalink。# hexo: _config.yml
permalink: :year/:month/:day/:title/
数据获取是区分静态生成和服务端渲染的关键。
next 提供多种获取方法。
getStaticProps 用于构建时获取数据。getServerSideProps 用于每次请求时获取数据。// next: getStaticProps
export async function getStaticProps() {
const res = await fetch('https://api.example.com/data');
return { props: { data: await res.json() } };
}
nuxt 使用 useFetch 或 asyncData。
<!-- nuxt: useFetch -->
<script setup>
const { data } = await useFetch('https://api.example.com/data');
</script>
gatsby 强制使用 GraphQL。
// gatsby: GraphQL Query
export const query = graphql`
query {
site { siteMetadata { title } }
}
`;
sapper 使用 preload 函数。
// sapper: preload
export async function preload() {
const res = await this.fetch('/api/data');
return { data: await res.json() };
}
hexo 不支持动态数据获取。
这是选型中最容易被忽视但最关键的一点。
sapper 已官方停止维护。
SvelteKit。sapper 将面临安全漏洞和兼容性问题。hexo 维护稳定但功能有限。
next、nuxt、gatsby 均活跃维护。
next 由 Vercel 支持,迭代最快。nuxt 社区活跃,Nuxt 3 性能提升明显。gatsby 转向云服务和内容管理,核心仍可用。| 特性 | next | nuxt | gatsby | hexo | sapper |
|---|---|---|---|---|---|
| 核心库 | React | Vue | React | Node.js | Svelte |
| 渲染模式 | SSR/SSG/ISR | SSR/SSG | SSG | SSG | SSR/SSG |
| 数据层 | 任意 API | 任意 API | GraphQL | 本地文件 | 任意 API |
| 适用场景 | 全栈应用 | 全栈应用 | 内容站点 | 博客 | 已弃用 |
| 维护状态 | ✅ 活跃 | ✅ 活跃 | ✅ 活跃 | ✅ 稳定 | ❌ 停止维护 |
对于新项目:
next。nuxt。gatsby。hexo 依然可靠。sapper,请直接选择 SvelteKit。架构决策核心: 不要只看流行度。问自己:我需要服务端逻辑吗?我需要频繁更新内容吗?我的团队熟悉什么框架?答案通常会直接指向其中一个选项。保持技术栈简单 — 能解决问题的工具就是最好的工具。
选择 gatsby 如果你主要构建内容驱动的网站(如文档、营销页),依赖 GraphQL 统一管理多源数据,且团队熟悉 React 生态。
选择 hexo 如果你只需要一个简单的博客或个人站点,不需要复杂的交互逻辑,偏好 Markdown 写作和轻量级部署。
选择 next 如果你需要基于 React 构建全栈应用,支持混合渲染模式(SSR/SSG/ISR),且需要强大的生态系统和企业级支持。适合电商、仪表盘和内容混合型网站。
选择 nuxt 如果你偏好 Vue 技术栈,需要类似 Next.js 的全栈能力,包括自动导入、服务端渲染和模块化架构。适合 Vue 团队构建高性能 Web 应用。
不要在新项目中选择 sapper。它已官方停止维护,功能被 SvelteKit 取代。如果维护旧项目,建议制定迁移计划至 SvelteKit。
The future of web development is here.
Gatsby is a free and open source framework based on React that helps developers build blazing fast websites and apps.
It combines the control and scalability of dynamically rendered sites with the speed of static-site generation, creating a whole new web of possibilities.
Gatsby helps professional developers efficiently create maintainable, highly-performant, content-rich websites.
Load Data From Anywhere. Gatsby pulls in data from any data source, whether it’s Markdown files, a headless CMS like Contentful or WordPress, or a REST or GraphQL API. Use source plugins to load your data, then develop using Gatsby’s uniform GraphQL interface.
Go Beyond Static Websites. Get all the benefits of static websites with none of the limitations. Gatsby sites are fully functional React apps, so you can create high-quality, dynamic web apps, from blogs to e-commerce sites to user dashboards.
Choose your Rendering Options. You can choose alternative rendering options, namely Deferred Static Generation (DSG) and Server-Side Rendering (SSR), in addition to Static Site Generation (SSG) — on a per-page basis. This type of granular control allows you to optimize for performance and productivity without sacrificing one for the other.
Performance Is Baked In. Ace your performance audits by default. Gatsby automates code splitting, image optimization, inlining critical styles, lazy-loading, prefetching resources, and more to ensure your site is fast — no manual tuning required.
Use a Modern Stack for Every Site. No matter where the data comes from, Gatsby sites are built using React and GraphQL. Build a uniform workflow for you and your team, regardless of whether the data is coming from the same backend.
Host at Scale for Pennies. Gatsby sites don’t require servers, so you can host your entire site on a CDN for a fraction of the cost of a server-rendered site. Many Gatsby sites can be hosted entirely free on Gatsby Cloud and other similar services.
Use Gatsby's Centralized Data Layer Everywhere. With Gatsby's Valhalla Content Hub you can bring Gatsby's data layer to any project. Making it accessible via a unified GraphQL API for building content sites, eCommerce platforms, and both native and web applications.
Learn how to use Gatsby for your next project.
Click the link below to quickly try the workflow of developing, building, and deploying websites with Gatsby and Gatsby Cloud.
At the end of this process, you'll have
You can get a new Gatsby site up and running on your local dev environment in 5 minutes with these four steps:
Initialize a new project.
npm init gatsby
Give it the name "My Gatsby Site".
Start the site in develop mode.
Next, move into your new site’s directory and start it up:
cd my-gatsby-site/
npm run develop
Open the source code and start editing!
Your site is now running at http://localhost:8000. Open the my-gatsby-site directory in your code editor of choice and edit src/pages/index.js. Save your changes, and the browser will update in real time!
At this point, you’ve got a fully functional Gatsby website. For additional information on how you can customize your Gatsby site, see our plugins and the official tutorial.
Full documentation for Gatsby lives on the website.
For most developers, we recommend starting with our in-depth tutorial for creating a site with Gatsby. It starts with zero assumptions about your level of ability and walks through every step of the process.
To dive straight into code samples head to our documentation. In particular, check out the “How-to Guides”, “Reference”, and “Conceptual Guides” sections in the sidebar.
We welcome suggestions for improving our docs. See the “how to contribute” documentation for more details.
Start Learning Gatsby: Follow the Tutorial · Read the Docs
Wondering what we've shipped recently? Check out our release notes for key highlights, performance improvements, new features, and notable bugfixes.
Also, read our documentation on version support to understand our plans for each version of Gatsby.
Already have a Gatsby site? These handy guides will help you add the improvements of Gatsby v5 to your site without starting from scratch!
Gatsby is dedicated to building a welcoming, diverse, safe community. We expect everyone participating in the Gatsby community to abide by our Code of Conduct. Please read it. Please follow it. In the Gatsby community, we work hard to build each other up and create amazing things together. 💪💜
Whether you're helping us fix bugs, improve the docs, or spread the word, we'd love to have you as part of the Gatsby community!
Check out our Contributing Guide for ideas on contributing and setup steps for getting our repositories up and running on your local machine.
This repository is a monorepo managed using Lerna. This means there are multiple packages managed in this codebase, even though we publish them to NPM as separate packages.
Licensed under the MIT License.
Thanks go out to all our many contributors creating plugins, starters, videos, and blog posts. And a special appreciation for our community members helping with issues and PRs, or answering questions on GitHub Discussions.
A big part of what makes Gatsby great is each and every one of you in the community. Your contributions enrich the Gatsby experience and make it better every day.