Deploying to Surge
In this guide, you will learn how to deploy your Gatsby site to Surge.
Surge is a cloud platform for hosting static websites, which is extremely simple to use but offers customization options for those who need them.
Their generous free tier permits unlimited publishing, using custom domains, basic SSL, with more features available in through the professional plan.
This guide will show you how to get started in a few quick steps:
Step 1: Getting Surge
To install the surge CLI with npm
, paste the following into your terminal:
npm install -g surge
Step 2: Preparing to Deploy
Build a site by running this command in your project’s root directory:
gatsby build
This generates a publishable version of your site in the ./public
folder.
Step 3: Deploying
You can deploy your site by running the following in the root of the project directory.
surge public/
If this is your first time using surge, you’ll be prompted to create a (free) account from the command line. This will only happen once.
Press enter
to confirm that the path to your public/
folder is correct, and that you’d like to keep the randomly generated subdomain name (it can be edited if not).
You’re done! Your terminal will output the address of the domain where your site was deployed.
Step 4: Bonus - Remembering a Domain
To ensure future deploys are sent to the same location, you can store the domain name in a CNAME
file from your project root. Assuming your site was deployed to https://my-cool-domain.surge.sh
, run the following command:
echo my-cool-domain.surge.sh > CNAME
Consult the Surge Docs for information about how to customize your deployment further. Remember that each time you redeploy your site, you will need to rerun gatsby build
first.
References:
Edit this page on GitHub