-
Set GitHub repo name in
sh ./deploy.sh
(not needed if using the root repo named<username>.github.io) -
Run
sh ./deploy.shto build, export, and deploy
Prepare the initial state of the app (as a starter for other projects)
-
Create a new repo on GitHub and name it
username.github.ioCheck to create the readme file to have a working repo with the green
Codebutton -
Run GitHub Codespaces
-
Install
Prettierplugin -
Adjust
VS Codesettings{ "editor.defaultFormatter": "esbenp.prettier-vscode", "editor.formatOnSave": true, "prettier.semi": false, "editor.tabSize": 2, "editor.lineHeight": 24, "terminal.integrated.lineHeight": 1.2, "terminal.integrated.letterSpacing": 1 }
-
Run installation command
npx create-next-app@latest
-
Choose the name app as
.(current directory)
Install Tailwind CSS with Next.js - Tailwind CSS
-
Install
Tailwind CSS IntelliSenseplugin inVS Code- this is important! -
Clean up
Next.jsdefault files (deleteapi,css modules) -
Check development preview
npm run dev
git add . && git commit -m "Set initial project state" && git pushCreate the app
Reuse existing components from the repo
Deploy the project
-
Add export command to
package.jsonand run it"export": "next build && next export"
-
Create a new
git-worktree(new branch accessible inside a folder)git worktree add gh-pages
-
Ignore that new folder from the main branch
In
.gitignoreadd:# github pages branch /gh-pages -
Remove all files from
gh-pagesdir, except.gitfolderfind gh-pages/ -mindepth 1 -not -name '.git' -delete -
Copy files from
outdir togh-pagescp -r out/* gh-pages -
Commit changes in
gh-pagesbranch and push themcd gh-pages && git add . && git commit -m 'Deploy' && git push --set-upstream origin gh-pages
-
Chain those commands in the bash script
deploy.sh#! /bin/bash # Install node_modules npm install # Build the Next.js app npx next build && # Export static files from the build (by default to the `out` dir) npx next export && # Create a branch `gh-pages` inside the folder git worktree add gh-pages # Delete all files inside `gh-pages` folder, except the `.git` (to preserve the worktree) find gh-pages/ -mindepth 1 -not -name '.git' -delete # Copy all files from the `out` to `gh-pages` folder cp -r out/* gh-pages/ && # Commit changes inside `gh-pages` folder/branch and push them to GitHub cd gh-pages && git add . && git commit -m 'Deploy' && git push --set-upstream origin gh-pages
-
Check the GitHub page setting
-
Remove Jekyll from the build chain by creating
.nojekyllfile ingh-pagesfolder/branch(with Jekyll, underscored names won’t work, like
_next) -
Include that in the deploy script (after deleting files in
gh-pages)# Disable Jekyll build process (https://docs.github.com/en/pages/getting-started-with-github-pages/about-github-pages#static-site-generators) touch gh-pages/.nojekyll
-
Use
GITHUB_REPOenv variable before the build script and update the deploy script:# Set the GitHub repo name and build the Next.js app GITHUB_REPO="" npx next build &&
-
Update
next.config.jsfile:const nextConfig = { // ... basePath: process.env.GITHUB_REPO ? `/${process.env.GITHUB_REPO}` : "", }