This article demonstrates how to create and deploy a Gatsby web application to Azure Static Web Apps. The final result is a new Static Web Apps site (with the associated GitHub Actions) that give you control over how the app is built and published.
Create a Gatsby app using the Gatsby Command Line Interface (CLI):
Open a terminal
Use the npx tool to create a new app with the Gatsby CLI. This may take a few minutes.
Bash
npx gatsby new static-web-app
Go to the newly created app
Bash
cd static-web-app
Initialize a Git repo
Bash
git init
git add -A
git commit -m "initial commit"
Note
If you are using the latest version of Gatsby you may need to modify the package.json to include
"engines": {
"node": ">=18.0.0"
},
Push your application to GitHub
You need to have a repository on GitHub to create a new Azure Static Web Apps resource.
Create a blank GitHub repository (don't create a README) from https://github.com/new named gatsby-static-web-app.
Next, add the GitHub repository you just created as a remote to your local repo. Make sure to add your GitHub username in place of the <YOUR_USER_NAME> placeholder in the following command.
Region for Azure Functions API and staging environments
Select a region closest to you.
Source
GitHub
Select Sign in with GitHub and authenticate with GitHub.
Enter the following GitHub values.
Property
Value
Organization
Select your desired GitHub organization.
Repository
Select gatsby-static-web-app.
Branch
Select main.
Note
If you don't see any repositories, you may need to authorize Azure Static Web Apps on GitHub.
Browse to your GitHub repository and go to Settings > Applications > Authorized OAuth Apps, select Azure Static Web Apps, and then select Grant. For organization repositories, you must be an owner of the organization to grant the permissions.
In the Build Details section, select Gatsby from the Build Presets drop-down and keep the default values.
Review and create
Select Review + Create to verify the details are all correct.
Select Create to start the creation of the App Service Static Web App and provision a GitHub Actions for deployment.
Once the deployment completes, select Go to resource.
On the resource screen, select the URL link to open your deployed application. You may need to wait a minute or two for the GitHub Actions to complete.
Clean up resources
If you're not going to continue to use this application, you can delete the Azure Static Web App resource through the following steps:
Build end-to-end solutions in Microsoft Azure to create Azure Functions, implement and manage web apps, develop solutions utilizing Azure storage, and more.