Recipes: Deploying Your Site
Showtime. Once you are happy with your site, you are ready to go live with it!
Preparing for deployment
Prerequisites
- A Gatsby site
- The Gatsby CLI installed
Directions
Stop your development server if it is running (
Ctrl + C
on your command line in most cases)For the standard site path at the root directory (
/
), rungatsby build
using the Gatsby CLI on the command line. The built files will now be in thepublic
folder.
- To include a site path other than
/
(such as/site-name/
), set a path prefix by adding the following to yourgatsby-config.js
and replacingyourpathprefix
with your desired path prefix:
There are a few reasons to do this — for instance, hosting a blog built with Gatsby on a domain with another site not built on Gatsby. The main site would direct to example.com
, and the Gatsby site with a path prefix could live at example.com/blog
.
- With a path prefix set in
gatsby-config.js
, rungatsby build
with the--prefix-paths
flag to automatically add the prefix to the beginning of all Gatsby site URLs and<Link>
tags.
- Make sure that your site looks the same when running
gatsby build
as withgatsby develop
. By runninggatsby serve
when you build your site, you can test out (and debug if necessary) the finished product before deploying it live.
Additional resources
- Walk through building and deploying an example site in tutorial part one
- Learn about performance optimization
- Read about other deployment related topics
- Check out the deployment docs for specific hosting platforms and how to deploy to them
Deploying to Netlify
Use netlify-cli
to deploy your Gatsby application without leaving the command-line interface.
Prerequisites
- A Gatsby site with a single component
index.js
- The netlify-cli package installed
- The Gatsby CLI installed
Directions
Build your gatsby application using
gatsby build
Login into Netlify using
netlify login
Run the command
netlify init
. Select the “Create & configure a new site” option.Choose a custom website name if you want or press enter to receive a random one.
Choose your Team.
Change the deploy path to
public/
Make sure that everything looks fine before deploying to production using
netlify deploy -d . --prod
Additional resources
Deploying to ZEIT Now
Use Now CLI to deploy your Gatsby application without leaving the command-line interface.
Prerequisites
- A ZEIT Now account
- A Gatsby site with a single component
index.js
- Now CLI package installed
- Gatsby CLI installed
Directions
Login into Now CLI using
now login
Change to the directory of your Gatsby.js application in the Terminal if you aren’t already there
Run
now
to deploy it
Additional resources
Edit this page on GitHub