To start the site in development mode:
gatsby develop
- Opens at
http://localhost:8000
- Live reload, fast refresh enabled
- Ignores
pathPrefix
, so URL paths are root-based (good for local dev)
If your site will be deployed under a subdirectory like https://username.github.io/my-site
, you need to test it locally with pathPrefix
.
- Set the
pathPrefix
ingatsby-config.js
:
module.exports = {
pathPrefix: "/my-site", // replace with your repo name
// other config...
}
- Build the site with prefix:
gatsby build --prefix-paths
- Serve the site locally:
gatsby serve --prefix-paths
- Opens at
http://localhost:9000/my-site/
- Good for verifying routing, assets, and links before pushing to GitHub Pages
npm install gh-pages --save-dev
"scripts": {
"develop": "gatsby develop",
"build": "gatsby build",
"serve": "gatsby serve",
"deploy": "gatsby build --prefix-paths && gh-pages -d public"
}
npm run deploy
- This builds the project with the correct path prefix and pushes the
public/
folder to thegh-pages
branch.
You can also manually test the build before deploying:
npm run build
gatsby serve --prefix-paths