Skip to main content

Recipes: Deploying Your Site

Showtime. Once you are happy with your site, you are ready to go live with it!

Preparing for deployment

Prerequisites

Directions

  1. Stop your development server if it is running (Ctrl + C on your command line in most cases)

  2. For the standard site path at the root directory (/), run gatsby build using the Gatsby CLI on the command line. The built files will now be in the public folder.

  1. To include a site path other than / (such as /site-name/), set a path prefix by adding the following to your gatsby-config.js and replacing yourpathprefix 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.

  1. With a path prefix set in gatsby-config.js, run gatsby build with the --prefix-paths flag to automatically add the prefix to the beginning of all Gatsby site URLs and <Link> tags.
  1. Make sure that your site looks the same when running gatsby build as with gatsby develop. By running gatsby serve when you build your site, you can test out (and debug if necessary) the finished product before deploying it live.

Additional resources

Deploying to Netlify

Use netlify-cli to deploy your Gatsby application without leaving the command-line interface.

Prerequisites

Directions

  1. Build your gatsby application using gatsby build

  2. Login into Netlify using netlify login

  3. Run the command netlify init. Select the “Create & configure a new site” option.

  4. Choose a custom website name if you want or press enter to receive a random one.

  5. Choose your Team.

  6. Change the deploy path to public/

  7. 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

Directions

  1. Login into Now CLI using now login

  2. Change to the directory of your Gatsby.js application in the Terminal if you aren’t already there

  3. Run now to deploy it

Additional resources


Edit this page on GitHub