Skip to content

Commit

Permalink
fix(docs): update Heroku deployment instructions (gatsbyjs#11601)
Browse files Browse the repository at this point in the history
## Description

- Added CLI instructions for adding Heroku buildpacks
- Removed misleading instructions.
  • Loading branch information
JustinTRoss authored and gurpreet-hanjra committed Feb 14, 2019
1 parent 2a8ce90 commit dd8ac4f
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions docs/docs/deploying-to-heroku.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ Set the `heroku/node.js` and `heroku-buildpack-static` buildpacks on your applic
}
```

Sometimes specifying buildpacks via the `app.json` file doesn’t work. If this is your case try to add them in the Heroku dashboard or via the CLI.
Sometimes specifying buildpacks via the `app.json` file doesn’t work. If this is your case, try to add them in the Heroku dashboard or via the CLI with the following commands:

```sh
$ heroku buildpacks:set heroku/node
$ heroku buildpacks:set https://github.com/heroku/heroku-buildpack-static.git
```

Add a `heroku-postbuild` script in your `package.json`:

Expand All @@ -31,24 +36,6 @@ Add a `heroku-postbuild` script in your `package.json`:
}
```

It is worth noting that, by default, creating a new project with `gatsby new <your-project-name>` creates a `package.json` with a `start` script as `npm run develop`. Without creating a Procfile to specify your commands to run for your process types, Heroku will run the web process via the `npm start` command by default. Since we've compiled our production-optimized build with `gatsby build`, the command we want to run is actually `gatsby serve`. To do this, either add the following script to your `package.json`:

```json:package.json
{
"scripts": {
"start": "gatsby serve --port ${PORT}"
}
}
```

Or, create a `Procfile`:

```title=Procfile
web: gatsby serve --port ${PORT}
```

The port needs to be specified to use the Heroku dyno's runtime environment variable in order to bind to the port correctly.

Finally, add a `static.json` file in the root of your project to define the directory where your static assets will be. You can check all the options for this file in the [heroku-buildpack-static](https://github.com/heroku/heroku-buildpack-static#configuration) configuration.

```json:title=static.json
Expand Down

0 comments on commit dd8ac4f

Please sign in to comment.