nextra
Simple, powerful and flexible site generation framework with everything you love from Next.js.
Top Related Projects
The React Framework
Easy to maintain open source documentation websites.
The best React-based framework with performance, scalability and security built in.
📝 Minimalistic Vue-powered static site generator
🃏 A magical documentation site generator.
The web framework for content-driven websites. ⭐️ Star to support our work!
Quick Overview
Nextra is a Next.js and MDX-based static site generator with built-in support for documentation and blog websites. It provides a simple and flexible way to create content-focused websites with minimal configuration, leveraging the power of React and Markdown.
Pros
- Easy to set up and use, with minimal configuration required
- Built-in support for documentation and blog layouts
- Seamless integration with Next.js and React ecosystem
- Customizable themes and components
Cons
- Limited to Next.js-based projects
- May have a steeper learning curve for those unfamiliar with React or Next.js
- Documentation could be more comprehensive for advanced use cases
Code Examples
- Creating a simple page:
// pages/index.mdx
# Welcome to My Nextra Site
This is a basic page created using Nextra.
## Features
- Easy to use
- Markdown support
- React components
- Using a React component within MDX:
import { Button } from '../components/Button'
# Interactive Page
Click the button below:
<Button onClick={() => alert('Hello!')}>
Click me
</Button>
- Configuring the theme:
// theme.config.js
export default {
logo: <span>My Project</span>,
project: {
link: 'https://github.com/username/project',
},
docsRepositoryBase: 'https://github.com/username/project/tree/main',
footer: {
text: '© 2023 My Project',
},
}
Getting Started
To start using Nextra, follow these steps:
- Install Nextra and its dependencies:
npm install next react react-dom nextra nextra-theme-docs
- Update your
next.config.js
:
const withNextra = require('nextra')({
theme: 'nextra-theme-docs',
themeConfig: './theme.config.js',
})
module.exports = withNextra()
- Create a
pages
directory and add your first MDX file:
# Welcome to Nextra
This is your first Nextra page.
- Run your development server:
npm run dev
Your Nextra site is now up and running!
Competitor Comparisons
The React Framework
Pros of Next.js
- More comprehensive and feature-rich framework for building React applications
- Larger community and ecosystem, with extensive documentation and third-party integrations
- Supports both static site generation (SSG) and server-side rendering (SSR) out of the box
Cons of Next.js
- Steeper learning curve for beginners due to its extensive feature set
- Can be overkill for simple projects or documentation sites
- Requires more configuration and setup compared to Nextra
Code Comparison
Next.js:
import { useRouter } from 'next/router'
function ActiveLink({ children, href }) {
const router = useRouter()
const style = { color: router.asPath === href ? 'red' : 'black' }
return <a href={href} style={style}>{children}</a>
}
Nextra:
import { useRouter } from 'next/router'
import Link from 'next/link'
function ActiveLink({ children, href }) {
const router = useRouter()
const isActive = router.asPath === href
return (
<Link href={href} className={isActive ? 'active' : ''}>{children}</Link>
)
}
Easy to maintain open source documentation websites.
Pros of Docusaurus
- More mature and feature-rich, with a larger ecosystem and community support
- Offers a wider range of themes and plugins out of the box
- Better internationalization support for multilingual documentation
Cons of Docusaurus
- Steeper learning curve due to more complex configuration options
- Heavier bundle size, which may impact initial load times
- Less flexible in terms of customization compared to Nextra's simplicity
Code Comparison
Nextra configuration (next.config.js):
const withNextra = require('nextra')({
theme: 'nextra-theme-docs',
themeConfig: './theme.config.js',
})
module.exports = withNextra()
Docusaurus configuration (docusaurus.config.js):
module.exports = {
title: 'My Site',
tagline: 'Documentation made easy',
url: 'https://your-docusaurus-site.com',
baseUrl: '/',
onBrokenLinks: 'throw',
onBrokenMarkdownLinks: 'warn',
favicon: 'img/favicon.ico',
// ... more configuration options
}
Both Nextra and Docusaurus are powerful static site generators for creating documentation websites. Nextra offers simplicity and ease of use, while Docusaurus provides a more comprehensive set of features and customization options. The choice between the two depends on the specific needs of your project and your familiarity with React and Next.js.
The best React-based framework with performance, scalability and security built in.
Pros of Gatsby
- Larger ecosystem with extensive plugins and themes
- More mature project with longer development history
- Supports a wider range of data sources and integrations
Cons of Gatsby
- Steeper learning curve, especially for React beginners
- Slower build times for large sites
- More complex configuration and setup process
Code Comparison
Nextra (Next.js-based) routing:
// pages/index.js
export default function Home() {
return <h1>Welcome to Nextra</h1>
}
Gatsby routing:
// src/pages/index.js
import React from "react"
export default function Home() {
return <h1>Welcome to Gatsby</h1>
}
Summary
Gatsby is a more established and feature-rich static site generator with a vast ecosystem. It offers greater flexibility for complex projects but comes with a steeper learning curve. Nextra, built on Next.js, provides a simpler and more streamlined approach, making it easier for beginners to get started. Gatsby excels in handling diverse data sources and integrations, while Nextra focuses on simplicity and ease of use for documentation and content-heavy sites. The choice between the two depends on project requirements, team expertise, and desired complexity level.
📝 Minimalistic Vue-powered static site generator
Pros of VuePress
- Built on Vue.js, offering a familiar ecosystem for Vue developers
- Extensive plugin system and theme customization options
- Strong documentation and community support
Cons of VuePress
- Slower build times for large sites compared to Nextra
- Less focus on modern React features and Next.js integration
Code Comparison
VuePress configuration:
module.exports = {
title: 'My Site',
description: 'A VuePress site',
themeConfig: {
nav: [{ text: 'Home', link: '/' }]
}
}
Nextra configuration:
export default {
logo: <span>My Site</span>,
project: { link: 'https://github.com/username/repo' },
docsRepositoryBase: 'https://github.com/username/repo/tree/main'
}
Key Differences
- VuePress is Vue-based, while Nextra is built on Next.js and React
- Nextra offers better performance for larger sites
- VuePress has a more mature ecosystem and plugin support
- Nextra provides seamless integration with Next.js features
Use Cases
- Choose VuePress for Vue-based projects or when extensive customization is needed
- Opt for Nextra for React projects, faster builds, and modern Next.js features
🃏 A magical documentation site generator.
Pros of Docsify
- Simpler setup and configuration, requiring minimal initial setup
- No build process needed, works directly with Markdown files
- Supports a wider range of plugins and themes out-of-the-box
Cons of Docsify
- Limited built-in features compared to Nextra's more comprehensive offering
- Less integration with React ecosystem and Next.js framework
- May require more custom JavaScript for advanced functionality
Code Comparison
Docsify configuration:
window.$docsify = {
name: 'My Documentation',
repo: 'https://github.com/user/repo',
loadSidebar: true,
subMaxLevel: 2
};
Nextra configuration:
export default {
logo: <span>My Project</span>,
project: { link: 'https://github.com/user/repo' },
docsRepositoryBase: 'https://github.com/user/repo/tree/main',
useNextSeoProps() {
return { titleTemplate: '%s – My Project' }
}
};
Both Docsify and Nextra offer streamlined documentation solutions, but they cater to different needs. Docsify excels in simplicity and quick setup, making it ideal for smaller projects or those preferring a lightweight solution. Nextra, built on Next.js, provides a more robust framework with enhanced React integration, making it suitable for larger, more complex documentation needs, especially within the React ecosystem.
The web framework for content-driven websites. ⭐️ Star to support our work!
Pros of Astro
- Supports multiple frontend frameworks (React, Vue, Svelte, etc.) in a single project
- Offers partial hydration for improved performance
- Has a larger community and ecosystem
Cons of Astro
- Steeper learning curve for developers new to static site generators
- Less focused on documentation-specific features compared to Nextra
Code Comparison
Astro:
---
const title = "My Astro Site";
---
<html>
<head><title>{title}</title></head>
<body><h1>{title}</h1></body>
</html>
Nextra:
import { useConfig } from 'nextra-theme-docs'
export default function Layout({ children }) {
const { title } = useConfig()
return <div><h1>{title}</h1>{children}</div>
}
Key Differences
- Astro uses a custom
.astro
file format, while Nextra leverages standard React components - Astro's component syntax separates frontmatter and markup, whereas Nextra uses JSX
- Nextra is more focused on documentation sites, while Astro is a general-purpose static site generator
Use Cases
- Choose Astro for multi-framework projects or when partial hydration is crucial
- Opt for Nextra when building documentation sites with Next.js and MDX
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Nextra
Simple, powerful and flexible site generation framework with everything you love from Next.js.
Documentation
Development
Installation
The Nextra repository uses PNPM Workspaces and Turborepo.
-
Run
corepack enable
to enable Corepack.If the command above fails, run
npm install -g corepack@latest
to install the latest version of Corepack. -
Run
pnpm install
to install the project's dependencies.
Build nextra
pnpm --filter nextra build
Watch mode: pnpm --filter nextra dev
Build nextra-theme-docs
pnpm --filter nextra-theme-docs build
Development
You can also debug them together with a website locally. For instance, to start
examples/docs
locally, run
pnpm --filter example-docs dev
Any change to example/docs
will be re-rendered instantly.
If you update the core or theme packages, a rebuild is required. Or you can use the watch mode for both Nextra and the theme in separated terminals.
Sponsors
Top Related Projects
The React Framework
Easy to maintain open source documentation websites.
The best React-based framework with performance, scalability and security built in.
📝 Minimalistic Vue-powered static site generator
🃏 A magical documentation site generator.
The web framework for content-driven websites. ⭐️ Star to support our work!
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot