Appendix A. The Gatsby CLI

The Gatsby CLI is the primary means of setting up, developing, and running a Gatsby application, including within a local development server and performing production builds.

Gatsby Cheat Sheet

First, install the global executable:

$ npm install -g gatsby-cli

Execute gatsby --help for a full list of available commands and options.

Common CLI Commands

Here’s a quick rundown of the commands you’ll use most often, covered in more detail in “Gatsby CLI Commands”:

gatsby new my-gatsby-site-name
Create a new local Gatsby site using the default starter.
gatsby develop

Start the Gatsby development server, optionally with the flags -H and --host.

Set the host. Defaults to localhost: -p, --port.

Set the port. Defaults to 8000: -o, --open.

Open the site in the default browser: -S, --https.

Use HTTPS.

gatsby build

Compile your application and prepare it for deployment, optionally with the flag --prefix-paths.

Build the site with link paths prefixed (after setting pathPrefix in gatsby-config.js): --no-uglify.

Build the site without uglifying JavaScript bundles (for debugging): --open-tracing-config-file.

Enable use of an OpenTracing-compatible configuration file.

gatsby serve

Serve the production build for testing, optionally with the flags -H and --host.

Set host. Defaults to localhost: -p, --port.

Set port. Defaults to 9000: -o, --open.

Open the site in the default browser: --prefix-paths.

Serve the site with link paths prefixed (if built with pathPrefix ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.