Skip to main content

Deploying to Now

ZEIT Now is a cloud platform for serverless deployment that you can use to deploy your Gatsby projects and alias them to your personal domain or a free .now.sh suffixed URL.

This guide will show you how to get started in a few quick steps:

Step 1: Getting Started with Gatsby

If you havenā€™t already set up a Gatsby project you can do so by first installing Gatsby globally:

npm install --global gatsby-cli

Then generate a project with the following command:

gatsby new <your project name>

Step 2: Getting Now

You can use Now by installing Now Desktop, which also installs Now CLI and keeps it up-to-date automatically.

To install Now CLI quickly with npm, use the following:

npm install -g now

Step 3: Preparing to Deploy

With Now CLI installed, we can go on to deploy our previously setup Gatsby project by first creating a now.json file with the following contents:

now.json
{
  "version": 2,
  "name": "my-gatsby-project",
  "builds": [
    {
      "src": "package.json",
      "use": "@now/static-build",
      "config": { "distDir": "public" }
    }
  ]
}

This now.json file will allow us to do several things, specifically:

The final step is to add a script to the package.json which will build our application:

package.json
{
  "scripts": {
    ...
    "now-build": "npm run build"
  }
}

Step 4: Deploying

You can deploy your application by running the following in the root of the project directory, where the now.json is:

now

Thatā€™s all! Your application will now deploy, and you will receive a link similar to the following: https://my-gatsby-project-fhcc9hnqc.now.sh/

References:


edit this page on GitHub