Chapter 12. Deploying Gatsby

Once you’ve done the work to spruce up your codebase (through best practices for testing and debugging your Gatsby site), it’s time to push your site into production so your users can begin to interact with your Gatsby implementation. Because it’s an SSG at its core, there are several aspects of Gatsby that require some unique approaches to handling deployments and managing environments. Unlike other JavaScript technologies like React or Angular, Gatsby requires a serverless approach to hosting infrastructure that may be unfamiliar.

In this chapter, we’ll start with a comprehensive introduction to how Gatsby handles environment variables, a subject we’ve touched on many times throughout this book but have not accorded its own full coverage. Then we’ll explore how to handle unusual hosting requirements such as assets hosted elsewhere and Gatsby sites located on paths other than domain roots. Finally, we’ll examine some of the most commonly used hosting infrastructure providers for Gatsby builds and deployments (Netlify, Vercel, Gatsby Cloud, and others), which each have independent and compelling advantages for developers working in their ecosystems.

Environment Variables

Gatsby developers can use environment variables to provide values that need to be distinct across development environments. They are most commonly used to obfuscate certain information that may be sensitive and should not be exposed to others.

Some environments require different information ...

Get Gatsby: The Definitive Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.