Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use App Router for static export example. #47584

Merged
merged 3 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/github-pages/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts

.vscode
2 changes: 1 addition & 1 deletion examples/github-pages/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Deploying to GitHub Pages

This example supports deloying a static Next.js application (using `next export`) to GitHub Pages.
This example supports deloying a statically exported Next.js application to GitHub Pages.

The `out` directory should not be ignored by version control.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import Link from 'next/link'

export default function About() {
return (
<div>
<div>About</div>
<>
<h1>About</h1>
<div>
Back to <Link href="/">Home</Link>
</div>
</div>
</>
)
}
11 changes: 11 additions & 0 deletions examples/github-pages/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
4 changes: 4 additions & 0 deletions examples/github-pages/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
* @type {import('next').NextConfig}
**/
const nextConfig = {
output: 'export',
basePath: '/gh-pages-test',
experimental: {
appDir: true,
},
}

module.exports = nextConfig
14 changes: 6 additions & 8 deletions examples/github-pages/package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
{
"private": true,
"scripts": {
"dev": "next",
"build": "next build && next export",
"dev": "next dev",
"build": "next build",
"deploy": "next build && touch out/.nojekyll && git add out/ && git commit -m \"Deploy\" && git subtree push --prefix out origin gh-pages"
},
"dependencies": {
"next": "latest",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/node": "^18.11.5",
"@types/react": "^18.0.23",
"@types/react-dom": "^18.0.7",
"@types/react": "^18.0.23",
"next": "latest",
"react-dom": "^18.2.0",
"react": "^18.2.0",
"typescript": "^4.8.4"
}
}
15 changes: 13 additions & 2 deletions examples/github-pages/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,19 @@
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true
"incremental": true,
"plugins": [
{
"name": "next"
}
]
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "next.config.js"],
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
"next.config.js",
".next/types/**/*.ts"
],
"exclude": ["node_modules"]
}
8 changes: 5 additions & 3 deletions examples/with-static-export/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Static export example
# Next.js Static Export

This example show how to export to static HTML files your Next.js application fetching data from an API to generate a dynamic list of pages.
Next.js enables starting as a static site or Single-Page Application (SPA), then later optionally upgrading to use features that require a server.

When trying to run `npm start` it will build and export your pages into the `out` folder and serve them on `localhost:3000`.
When running `next build`, Next.js generates an HTML file per route. By breaking a strict SPA into individual HTML files, Next.js can avoid loading unnecessary JavaScript code on the client-side, reducing the bundle size and enabling faster page loads.

Learn more: https://beta.nextjs.org/docs/configuring/static-export

## Deploy your own

Expand Down
12 changes: 12 additions & 0 deletions examples/with-static-export/app/about/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Link from 'next/link'

export default function About() {
return (
<>
<h1>About</h1>
<div>
Back to <Link href="/">Home</Link>
</div>
</>
)
}
11 changes: 11 additions & 0 deletions examples/with-static-export/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
9 changes: 9 additions & 0 deletions examples/with-static-export/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Link from 'next/link'

export default function Home() {
return (
<div>
Hello World. <Link href="/about">About</Link>
</div>
)
}
12 changes: 0 additions & 12 deletions examples/with-static-export/components/post.tsx

This file was deleted.

17 changes: 0 additions & 17 deletions examples/with-static-export/lib/postdata_api.ts

This file was deleted.

13 changes: 13 additions & 0 deletions examples/with-static-export/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// @ts-check

/**
* @type {import('next').NextConfig}
**/
const nextConfig = {
output: 'export',
experimental: {
appDir: true,
},
}

module.exports = nextConfig
22 changes: 7 additions & 15 deletions examples/with-static-export/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,16 @@
"scripts": {
"dev": "next",
"build": "next build",
"preexport": "npm run build",
"export": "next export",
"prestart": "npm run export",
"start": "serve out",
"lint": "next lint"
"start": "serve out"
},
"dependencies": {
"@types/node": "^18.11.5",
"@types/react-dom": "^18.0.7",
"@types/react": "^18.0.23",
"next": "latest",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"serve": "^14.0.1"
},
"devDependencies": {
"@types/node": "^18.0.0",
"@types/react": "^18.0.14",
"@types/react-dom": "^18.0.5",
"eslint": "8.19.0",
"eslint-config-next": "12.2.0",
"typescript": "^4.7.4"
"react": "^18.2.0",
"serve": "^14.0.1",
"typescript": "^4.8.4"
}
}
37 changes: 0 additions & 37 deletions examples/with-static-export/pages/index.tsx

This file was deleted.

55 changes: 0 additions & 55 deletions examples/with-static-export/pages/post/[id].tsx

This file was deleted.

17 changes: 14 additions & 3 deletions examples/with-static-export/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,25 @@
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"incremental": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"moduleResolution": "node"
"incremental": true,
"plugins": [
{
"name": "next"
}
]
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
"next.config.js",
".next/types/**/*.ts"
],
"exclude": ["node_modules"]
}
14 changes: 0 additions & 14 deletions examples/with-static-export/types/postdata.ts

This file was deleted.